{"record":{"id":"2d5beee8fd644310","repo":"GoogleContainerTools/jib","slug":"the-class-file-jarentry-is-of-an-invalid-form","errorCode":null,"errorMessage":"The class file (${jarEntry}) is of an invalid format.","messagePattern":"The class file \\((.+?)\\) is of an invalid format\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"jib-cli/src/main/java/com/google/cloud/tools/jib/cli/ArtifactProcessors.java","lineNumber":151,"sourceCode":"   * the JAR.\n   *\n   * @param jarPath path to the jar\n   * @return java version\n   * @throws IOException if I/O exception thrown when opening the jar file\n   */\n  public static Integer determineJavaMajorVersion(Path jarPath) throws IOException {\n    try (JarFile jarFile = new JarFile(jarPath.toFile())) {\n      Enumeration<JarEntry> jarEntries = jarFile.entries();\n      while (jarEntries.hasMoreElements()) {\n        String jarEntry = jarEntries.nextElement().toString();\n        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;","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/ArtifactProcessors.java#L133-L169","documentation":"determineJavaMajorVersion() reads the first class file found in the JAR to detect its Java version. It throws IllegalArgumentException when the class file's magic number is not 0xCAFEBABE, meaning the entry is not a valid Java class file and the version cannot be determined.","triggerScenarios":"The first .class entry in the JAR is corrupt, truncated, encrypted, or is not actually a class file (e.g. a mislabeled resource, a jar signed/obfuscated so the first entry is a manifest-relative fake .class, or a non-JVM artifact named .jar).","commonSituations":"Pointing jib at a fat jar produced by an unusual packager, a corrupted artifact from a partial upload, or a renamed zip that is not a JAR.","solutions":["Rebuild the JAR and verify it with `jar tf` / opening it in an IDE","Ensure the JAR is a genuine Java artifact containing valid .class files","Check for corruption: compare the artifact checksum with the one published by the build"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify the artifact is a real jar before processing\nif (!Files.exists(jarPath) || Files.size(jarPath) < 100) throw new IOException(\"suspicious jar: \" + jarPath);","typeGuard":null,"tryCatchPattern":"try { int v = determineJavaMajorVersion(jarPath); } catch (IllegalArgumentException e) { /* report corrupt/invalid class file; rebuild or re-fetch the jar */ }","preventionTips":["Verify artifact checksums after download/CI transfer","Validate jars with `jar tf` before feeding them to jib","Rebuild jars produced by interrupted or disk-full builds"],"tags":["jib","cli","class-file","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"}