GoogleContainerTools/jib · warning
Invalid class file found: ${file}
Error message
Invalid class file found: ${file} What it means
During main class discovery, Jib parses each candidate .class file with ASM's ClassReader; when the bytes are not a valid class file (ASM throws ArrayIndexOutOfBoundsException), Jib logs this warning and skips the file instead of failing the build.
Source
Thrown at jib-core/src/main/java/com/google/cloud/tools/jib/api/MainClassFinder.java:242
MainClassVisitor mainClassVisitor = new MainClassVisitor();
try (InputStream classFileInputStream = Files.newInputStream(file)) {
ClassReader reader = new ClassReader(classFileInputStream);
reader.accept(mainClassVisitor, 0);
if (mainClassVisitor.visitedMainClass) {
mainClasses.add(reader.getClassName().replace('/', '.'));
}
} catch (IllegalArgumentException ex) {
throw new UnsupportedOperationException(
"Check the full stace trace, and if the root cause is from ASM ClassReader about "
+ "unsupported class file version, see "
+ "https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md"
+ "#i-am-seeing-unsupported-class-file-major-version-when-building",
ex);
} catch (ArrayIndexOutOfBoundsException ignored) {
// Not a valid class file (thrown by ClassReader if it reads an invalid format)
logger.accept(LogEvent.warn("Invalid class file found: " + file));
} catch (IOException ignored) {
// Could not read class file.
logger.accept(LogEvent.warn("Could not read file: " + file));
}
}
if (mainClasses.size() == 1) {
// Valid class found.
return Result.success(mainClasses.get(0));
}
if (mainClasses.isEmpty()) {
// No main class found anywhere.
return Result.mainClassNotFound();
}
// More than one main class found.
return Result.multipleMainClasses(mainClasses);
}View on GitHub (pinned to fb949e2676)
Solutions
- Run a clean rebuild (mvn clean install / gradle clean build) to remove corrupted class files
- Locate and inspect the offending file named in the warning; delete or fix it
- Ensure only compiled Java classes are in the classes output directory
Example fix
// before (shell) # build has stale/corrupt target/classes/foo.class mvn jib:build // after mvn clean jib:build
Defensive patterns
Strategy: validation
Validate before calling
// Verify class files are readable valid JVM class files before building
byte[] bytes = java.nio.file.Files.readAllBytes(path);
if (bytes.length < 8 || (bytes[0] & 0xFF) != 0xCA || (bytes[1] & 0xFF) != 0xFE)
System.err.println("Not a valid class file: " + path); Prevention
- Run `clean` builds so stale/truncated .class files are purged
- Do not place non-class resources with a .class extension in the classes dir
- Watch for this warning after interrupted compilations
When it happens
Trigger: MainClassFinder.find() iterates class files in the classes directory; reading a file whose content is not a valid JVM class file format (corrupted build output, a non-class file with .class extension, truncated/incompatible class version handled elsewhere) triggers the catch (ArrayIndexOutOfBoundsException) branch.
Common situations: Interrupted compilations leaving truncated .class files; resource files accidentally named *.class; stale classes from a different JDK being read by incompatible tooling.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- The class file (${jarEntry}) is of an invalid format.
- Reached end of class file (${jarEntry}) before being able to
- error running extension '<extensionClassName>': <message>
- Failed to generate a Jib file map for sync with Skaffold
- No classes files were found - did you compile your project?
AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06).
Data as JSON: /api/errors/b19570d28f3b7ba3.
Report an issue: GitHub.