{"record":{"id":"ab9d1442e15c9446","repo":"elastic/elasticsearch","slug":"failed-when-reading-jar-file-path","errorCode":null,"errorMessage":"Failed when reading jar file ${path}","messagePattern":"Failed when reading jar file (.+?)","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionModuleCheckTaskProvider.java","lineNumber":122,"sourceCode":"                    } catch (IOException e) {\n                        throw new UncheckedIOException(e);\n                    }\n                }\n            });\n        });\n    }\n\n    /** Checks that all expected ES jar files are modular, i.e. contain a module-info.class in their root. */\n    private static void assertAllESJarsAreModular(Path libPath) throws IOException {\n        try (var s = Files.walk(libPath, 1)) {\n            s.filter(Files::isRegularFile).filter(isESJar).filter(isNotExcluded).sorted().forEach(path -> {\n                try (JarFile jf = new JarFile(path.toFile())) {\n                    JarEntry entry = jf.getJarEntry(MODULE_INFO);\n                    if (entry == null) {\n                        throw new GradleException(MODULE_INFO + \" no found in \" + path);\n                    }\n                } catch (IOException e) {\n                    throw new GradleException(\"Failed when reading jar file \" + path, e);\n                }\n            });\n        }\n    }\n\n    /** Checks that all expected Elasticsearch modules are present. */\n    private static void assertAllModulesPresent(Path libPath) {\n        List<String> actualESModules = ModuleFinder.of(libPath).findAll().stream().filter(isESModule).map(toName).sorted().toList();\n        if (actualESModules.equals(EXPECTED_ES_SERVER_MODULES) == false) {\n            throw new GradleException(\n                \"expected modules \" + listToString(EXPECTED_ES_SERVER_MODULES) + \", \\nactual modules \" + listToString(actualESModules)\n            );\n        }\n    }\n\n    // ####: eventually assert hashes, etc\n\n    static String listToString(List<String> list) {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionModuleCheckTaskProvider.java#L104-L140","documentation":"Thrown as GradleException by assertAllESJarsAreModular()'s catch(IOException) when opening or reading an ES jar file with new JarFile(path.toFile()) fails. This is the I/O-error counterpart to the missing-module-info check: the jar exists but is corrupted, truncated, unreadable, or in an invalid zip format.","triggerScenarios":"The try block at line 116 opens a new JarFile. If the file is not a valid zip/jar (truncated download, concurrent write, corrupted archive, zero-byte file), the IOException is caught at line 121 and rethrown as GradleException with the path.","commonSituations":"A previous build task was interrupted leaving a truncated jar in lib/; disk corruption; antivirus quarantined part of the jar; a symlink in lib/ pointing to a missing target; the jar is still being written by a concurrent process when checkModules runs.","solutions":["Delete the offending jar and rebuild the distribution: rm <path> && ./gradlew :distribution:archives:<name>:build.","Verify the file is a valid zip: unzip -l <path> or jar tf <path>.","Check for symlinks or concurrent processes writing to lib/.","If recurring, run with --info to see which task produced the corrupt jar."],"exampleFix":"# before: truncated/corrupt jar in lib/\n# throws: Failed when reading jar file .../lib/elasticsearch-server-9.0.0.jar\n\n# after: clean and rebuild\nrm .../lib/elasticsearch-server-9.0.0.jar\n./gradlew :distribution:archives:linux-tar:assemble","handlingStrategy":"validation","validationCode":"if (Files.size(path) < 22 || isValidZip(path) == false) {\n    System.err.println(\"WARNING: jar appears corrupt/truncated: \" + path);\n}","typeGuard":null,"tryCatchPattern":"try (JarFile jf = new JarFile(path.toFile())) {\n    // use jf\n} catch (IOException e) {\n    throw new GradleException(\"Failed when reading jar file \" + path, e);\n}","preventionTips":["Clean the build directory before rebuilding if jars may be truncated from interrupted builds.","Validate jars with 'jar tf' or 'unzip -t' before running checkModules.","Exclude lib/ from concurrent processes and antivirus locking.","Re-run the distribution build if a jar fails to open."],"tags":["distribution","io","modules","jar","corruption"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}