{"record":{"id":"00c0abc5a1f32874","repo":"GoogleContainerTools/jib","slug":"could-not-read-file-file","errorCode":null,"errorMessage":"Could not read file: ${file}","messagePattern":"Could not read file: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/api/MainClassFinder.java","lineNumber":246,"sourceCode":"        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  }\n}\n","sourceCodeStart":228,"sourceCodeEnd":262,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/api/MainClassFinder.java#L228-L262","documentation":"During main class discovery, Jib logs this warning when a candidate .class file cannot be read from disk (IOException), then skips it. Main class detection continues with the remaining files; only when zero or multiple main classes remain does the build fail separately.","triggerScenarios":"MainClassFinder.find() catches IOException from reading a class file's bytes (permission problems, file deleted mid-scan, I/O errors) and logs \"Could not read file: <file>\".","commonSituations":"Files with restrictive permissions in the classes directory; build output being concurrently modified during scanning; unreadable mounted volumes in containerized builds.","solutions":["Fix read permissions on the classes output directory and files","Run a clean rebuild to regenerate a consistent classes directory","Ensure no concurrent process deletes files while the build runs","Specify the main class explicitly so discovery is not needed"],"exampleFix":"// before (shell)\nchmod 600 target/classes/com/app/Main.class\nmvn jib:build\n// after\nchmod 644 target/classes/com/app/Main.class\n# or skip discovery entirely:\nmvn jib:build -Djib.mainClass=com.app.Main","handlingStrategy":"validation","validationCode":"// Pre-check that all files in the classes dir are readable\ntry (var s = java.nio.file.Files.walk(classesDir)) {\n  s.filter(java.nio.file.Files::isRegularFile)\n   .filter(p -> !java.nio.file.Files.isReadable(p))\n   .forEach(p -> System.err.println(\"Unreadable class file: \" + p));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the classes output directory has uniform read permissions","Avoid concurrent builds writing/deleting the same classes directory","Set the main class explicitly to bypass discovery"],"tags":["jib","io","file-read"],"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"}