{"record":{"id":"b19570d28f3b7ba3","repo":"GoogleContainerTools/jib","slug":"invalid-class-file-found-file","errorCode":null,"errorMessage":"Invalid class file found: ${file}","messagePattern":"Invalid class file found: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/api/MainClassFinder.java","lineNumber":242,"sourceCode":"      MainClassVisitor mainClassVisitor = new MainClassVisitor();\n      try (InputStream classFileInputStream = Files.newInputStream(file)) {\n        ClassReader reader = new ClassReader(classFileInputStream);\n        reader.accept(mainClassVisitor, 0);\n        if (mainClassVisitor.visitedMainClass) {\n          mainClasses.add(reader.getClassName().replace('/', '.'));\n        }\n\n      } catch (IllegalArgumentException ex) {\n        throw new UnsupportedOperationException(\n            \"Check the full stace trace, and if the root cause is from ASM ClassReader about \"\n                + \"unsupported class file version, see \"\n                + \"https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md\"\n                + \"#i-am-seeing-unsupported-class-file-major-version-when-building\",\n            ex);\n\n      } catch (ArrayIndexOutOfBoundsException ignored) {\n        // Not a valid class file (thrown by ClassReader if it reads an invalid format)\n        logger.accept(LogEvent.warn(\"Invalid class file found: \" + file));\n\n      } catch (IOException ignored) {\n        // Could not read class file.\n        logger.accept(LogEvent.warn(\"Could not read file: \" + file));\n      }\n    }\n\n    if (mainClasses.size() == 1) {\n      // Valid class found.\n      return Result.success(mainClasses.get(0));\n    }\n    if (mainClasses.isEmpty()) {\n      // No main class found anywhere.\n      return Result.mainClassNotFound();\n    }\n    // More than one main class found.\n    return Result.multipleMainClasses(mainClasses);\n  }","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/api/MainClassFinder.java#L224-L260","documentation":"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.","triggerScenarios":"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.","commonSituations":"Interrupted compilations leaving truncated .class files; resource files accidentally named *.class; stale classes from a different JDK being read by incompatible tooling.","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"],"exampleFix":"// before (shell)\n# build has stale/corrupt target/classes/foo.class\nmvn jib:build\n// after\nmvn clean jib:build","handlingStrategy":"validation","validationCode":"// Verify class files are readable valid JVM class files before building\nbyte[] bytes = java.nio.file.Files.readAllBytes(path);\nif (bytes.length < 8 || (bytes[0] & 0xFF) != 0xCA || (bytes[1] & 0xFF) != 0xFE)\n  System.err.println(\"Not a valid class file: \" + path);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["jib","class-file","build"],"backgroundTag":"file-read-failed","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}