我们有一个使用 update4j 的应用程序,并从 Windows 用户那里获得了错误报告,其中包含以下堆栈跟踪:
INFO [main] (OurMain.java:70) - Fatal error details: A problem occurred during the update
com.example.updater.RuntimeFatalError: A problem occured during the update
at com.example.updater.Updater.update(Updater.java:72)
...
Caused by: com.example.updater.RuntimeFatalError: A problem occurred during the update
at com.example.updater.UpdateHandler.failed(UpdateHandler.java:78)
at org.update4j.Configuration.updateImpl(Configuration.java:1048)
at org.update4j.Configuration.update(Configuration.java:861)
at org.update4j.Configuration.update(Configuration.java:845)
at com.example.updater.Updater.update(Updater.java:70)
... 1 common frames omitted
Caused by: java.io.IOException: Adathiba (CRC)
at java.base/sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at java.base/sun.nio.ch.FileDispatcherImpl.read(FileDispatcherImpl.java:54)
at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276)
at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:245)
at java.base/sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:223)
at java.base/sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65)
at java.base/sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109)
at java.base/sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
at org.update4j.util.FileUtils.getChecksum(FileUtils.java:57)
at org.update4j.FileMetadata.requiresUpdate(FileMetadata.java:371)
at org.update4j.Configuration.updateImpl(Configuration.java:934)
... 4 common frames omitted
(我猜“Adathiba (CRC)”消息在英语语言环境中将是“数据错误 (CRC)”。)
如果我是对的,update4j 正在尝试从此处的磁盘读取 jar 文件。
用户删除了我们的应用程序并完全重新安装了它(这解决了问题),但如果能够重现该错误并实际修复它,那就太好了,因为我们收到了其他一些类似的错误报告(不幸的是,细节更少)。
我尝试创建损坏的输入 zip/jar 文件,但 update4j 检测到其校验和与其 XML 文件中的校验和不同,并下载并替换了该文件(如预期)。
欢迎引用相关的 OpenJDK (13, 14) 源代码。我检查了 FileDispatcherImpl.java
和 FileDispatcherImpl.c
但没有发现任何与 CRC 检查或错误相关的内容。
所以,这是我的问题:
- 在什么情况下 JVM 会抛出这种
IOException
? - 这是否表明 ZIP/JAR 文件已损坏?如果是,如何创建一个导致类似异常的文件(用于测试)?
- 这是否表明硬盘有故障(并且错误来自操作系统)?
最佳答案
正如 @vbezhenar 在他的评论中提到的,这似乎是 native 操作系统错误消息。我不熟悉 JDK 代码,所以请谨慎对待我的(部分)答案。
FileDispatcherImpl.read0(Native Method)
(来自堆栈跟踪)是一个 native 方法:
static native int read0(FileDescriptor fd, long address, int len)
throws IOException;
它在 FileDispatcherImpl.c
source file 中实现如果我是对的
return convertReturnVal(env, (jint)read, JNI_TRUE);
语句抛出上面的异常。
convertReturnVal()
is implemented in the IOUtil.c
file 。它调用另一个方法:
JNU_ThrowIOExceptionWithLastError(env, "Read/write failed");
它在jni_util.c
文件中实现,第二个参数被命名为defaultDetail
。它调用
JNU_ThrowByNameWithLastError()
仅解析 ReadFile()
的结果(从 read0()
调用)。由于 defaultDetail
的值(读/写失败
)未显示在问题的堆栈跟踪中,我认为该消息来自操作系统。
关于java - 重现java.io.IOException : Data error (CRC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61007852/