GoogleContainerTools/jib · error · IllegalArgumentException
Reached end of class file (${jarEntry}) before being able to
Error message
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. What it means
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.
Source
Thrown at jib-cli/src/main/java/com/google/cloud/tools/jib/cli/ArtifactProcessors.java:162
if (jarEntry.endsWith(".class") && !jarEntry.endsWith("module-info.class")) {
try (URLClassLoader loader = new URLClassLoader(new URL[] {jarPath.toUri().toURL()});
DataInputStream classFile =
new DataInputStream(loader.getResourceAsStream(jarEntry))) {
// Check magic number
if (classFile.readInt() != 0xCAFEBABE) {
throw new IllegalArgumentException(
"The class file (" + jarEntry + ") is of an invalid format.");
}
// Skip over minor version
classFile.skipBytes(2);
int majorVersion = classFile.readUnsignedShort();
int javaVersion = (majorVersion - 45) + 1;
return javaVersion;
} catch (EOFException ex) {
throw new IllegalArgumentException(
"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.");
}
}
}
return VERSION_NOT_FOUND;
}
}
}
View on GitHub (pinned to fb949e2676)
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
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure the jar entry is large enough to contain magic + version fields
try (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()); } Try / catch
try { int v = determineJavaMajorVersion(jarPath); } catch (IllegalArgumentException e) { /* handle truncated/corrupt class file: rebuild jar and retry */ } Prevention
- Check class file sizes (>= 8 bytes) when generating jars
- Avoid partial uploads: use atomic artifact writes
- Re-verify cached CI artifacts after interrupted builds
When it happens
Trigger: 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.
Common situations: Partial downloads/CI artifact caching corruption; jars produced by a failed or disk-full build; empty class files committed/generated by annotation processors.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- The class file (${jarEntry}) is of an invalid format.
- octalPermissions must be a 3-digit octal number (000-777)
- The input JAR (${jarPath}) is compiled with Java ${jarJavaVe
- Please set the app root of the container with `--app-root` w
- Missing option: --name must be specified when using --target
AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06).
Data as JSON: /api/errors/da3423ae2ac8372b.
Report an issue: GitHub.