【问题标题】:Reproduce java.io.IOException: Data error (CRC)重现 java.io.IOException: 数据错误 (CRC)
【发布时间】:2020-04-03 08:28:27
【问题描述】:

我们有一个使用 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.javaFileDispatcherImpl.c,但没有发现任何与CRC 检查或错误相关的内容。

所以,这是我的问题:

  • 在什么情况下JVM会抛出这种IOException
  • 这是否表明 ZIP/JAR 文件已损坏?如果是,如何创建导致类似异常的文件(用于测试)?
  • 这是否表明硬盘出现故障(并且错误来自操作系统)?

【问题讨论】:

  • 本机方法抛出此异常。这意味着它是操作系统错误。很可能它表明有故障的硬盘。您可以尝试破解 Jimfs 来模拟该错误。

标签: java crc


【解决方案1】:

正如@vbezhenar 在他的评论中提到的,这似乎是一条原生操作系统错误消息。我对 JDK 代码不熟悉,所以请谨慎对待我的(部分)答案。

FileDispatcherImpl.read0(Native Method)(来自堆栈跟踪)是本机方法:

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 (Read/write failed) 的值未显示在问题的堆栈跟踪中,我想该消息来自操作系统。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2012-06-18
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    相关资源
    最近更新 更多