{"record":{"id":"da3423ae2ac8372b","repo":"GoogleContainerTools/jib","slug":"reached-end-of-class-file-jarentry-before-bei","errorCode":null,"errorMessage":"Reached end of class file (${jarEntry}) before being able to read the java major version. Make sure that the file is of the correct format.","messagePattern":"Reached end of class file \\((.+?)\\) before being able to read the java major version\\. Make sure that the file is of the correct format\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"jib-cli/src/main/java/com/google/cloud/tools/jib/cli/ArtifactProcessors.java","lineNumber":162,"sourceCode":"        if (jarEntry.endsWith(\".class\") && !jarEntry.endsWith(\"module-info.class\")) {\n          try (URLClassLoader loader = new URLClassLoader(new URL[] {jarPath.toUri().toURL()});\n              DataInputStream classFile =\n                  new DataInputStream(loader.getResourceAsStream(jarEntry))) {\n\n            // Check magic number\n            if (classFile.readInt() != 0xCAFEBABE) {\n              throw new IllegalArgumentException(\n                  \"The class file (\" + jarEntry + \") is of an invalid format.\");\n            }\n\n            // Skip over minor version\n            classFile.skipBytes(2);\n\n            int majorVersion = classFile.readUnsignedShort();\n            int javaVersion = (majorVersion - 45) + 1;\n            return javaVersion;\n          } catch (EOFException ex) {\n            throw new IllegalArgumentException(\n                \"Reached end of class file (\"\n                    + jarEntry\n                    + \") before being able to read the java major version. Make sure that the file is of the correct format.\");\n          }\n        }\n      }\n      return VERSION_NOT_FOUND;\n    }\n  }\n}\n","sourceCodeStart":144,"sourceCodeEnd":173,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/ArtifactProcessors.java#L144-L173","documentation":"determineJavaMajorVersion() catches EOFException while reading the class file's version fields and rethrows it as IllegalArgumentException: the file ended before the magic number/minor/major version could be read, so it is truncated or not a real class file.","triggerScenarios":"A .class entry in the JAR is truncated or empty (e.g. 0 bytes, or shorter than the 8 bytes needed for magic + versions), often from interrupted builds or corrupt artifacts.","commonSituations":"Partial downloads/CI artifact caching corruption; jars produced by a failed or disk-full build; empty class files committed/generated by annotation processors.","solutions":["Rebuild the JAR and verify class files with `javap -verbose` or `jar xf`","Delete corrupted cached/downloaded artifacts and re-fetch","Run the build again ensuring no disk-full/interrupted writes"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure the jar entry is large enough to contain magic + version fields\ntry (JarFile jar = new JarFile(jarPath.toFile())) { JarEntry e = jar.stream().filter(n -> n.getName().endsWith(\".class\")).findFirst().orElseThrow(() -> new IOException(\"no class files\")); if (e.getSize() < 8) throw new IOException(\"truncated class entry: \" + e.getName()); }","typeGuard":null,"tryCatchPattern":"try { int v = determineJavaMajorVersion(jarPath); } catch (IllegalArgumentException e) { /* handle truncated/corrupt class file: rebuild jar and retry */ }","preventionTips":["Check class file sizes (>= 8 bytes) when generating jars","Avoid partial uploads: use atomic artifact writes","Re-verify cached CI artifacts after interrupted builds"],"tags":["jib","cli","class-file","eof","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}