elastic/elasticsearch · error · GradleException
Failed when reading jar file ${path}
Error message
Failed when reading jar file ${path} What it means
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.
Source
Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionModuleCheckTaskProvider.java:122
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
});
}
/** Checks that all expected ES jar files are modular, i.e. contain a module-info.class in their root. */
private static void assertAllESJarsAreModular(Path libPath) throws IOException {
try (var s = Files.walk(libPath, 1)) {
s.filter(Files::isRegularFile).filter(isESJar).filter(isNotExcluded).sorted().forEach(path -> {
try (JarFile jf = new JarFile(path.toFile())) {
JarEntry entry = jf.getJarEntry(MODULE_INFO);
if (entry == null) {
throw new GradleException(MODULE_INFO + " no found in " + path);
}
} catch (IOException e) {
throw new GradleException("Failed when reading jar file " + path, e);
}
});
}
}
/** Checks that all expected Elasticsearch modules are present. */
private static void assertAllModulesPresent(Path libPath) {
List<String> actualESModules = ModuleFinder.of(libPath).findAll().stream().filter(isESModule).map(toName).sorted().toList();
if (actualESModules.equals(EXPECTED_ES_SERVER_MODULES) == false) {
throw new GradleException(
"expected modules " + listToString(EXPECTED_ES_SERVER_MODULES) + ", \nactual modules " + listToString(actualESModules)
);
}
}
// ####: eventually assert hashes, etc
static String listToString(List<String> list) {View on GitHub (pinned to db6a809a66)
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.
Example fix
# before: truncated/corrupt jar in lib/ # throws: Failed when reading jar file .../lib/elasticsearch-server-9.0.0.jar # after: clean and rebuild rm .../lib/elasticsearch-server-9.0.0.jar ./gradlew :distribution:archives:linux-tar:assemble
Defensive patterns
Strategy: validation
Validate before calling
if (Files.size(path) < 22 || isValidZip(path) == false) {
System.err.println("WARNING: jar appears corrupt/truncated: " + path);
} Try / catch
try (JarFile jf = new JarFile(path.toFile())) {
// use jf
} catch (IOException e) {
throw new GradleException("Failed when reading jar file " + path, e);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Can't walk source {}
- Could not write config file: {}
- Unable to read from file ${path}
- module-info.class no found in ${path}
- expected modules ${listToString(EXPECTED_ES_SERVER_MODULES)}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/ab9d1442e15c9446.
Report an issue: GitHub.