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

  1. Rebuild the JAR and verify class files with `javap -verbose` or `jar xf`
  2. Delete corrupted cached/downloaded artifacts and re-fetch
  3. 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

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


AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06). Data as JSON: /api/errors/da3423ae2ac8372b. Report an issue: GitHub.