elastic/elasticsearch · error · GradleException
Unable to read from file ${path}
Error message
Unable to read from file ${path} What it means
Thrown as GradleException by assertLinesInFile()'s catch(IOException) block when Files.readAllLines(path) fails for the file being checked. This is the I/O-failure counterpart to the line-mismatch error: the file exists (or doesn't) but cannot be read — missing file, permission denied, or encoding error.
Source
Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveCheckPlugin.java:207
t.eachFile(fileCopyDetails -> assertNoClassFile(fileCopyDetails.getFile()));
});
}
private static void assertLinesInFile(Path path, List<String> expectedLines) {
try {
final List<String> actualLines = Files.readAllLines(path);
int line = 0;
for (final String expectedLine : expectedLines) {
final String actualLine = actualLines.get(line);
if (expectedLine.equals(actualLine) == false) {
throw new GradleException(
"expected line [" + (line + 1) + "] in [" + path + "] to be [" + expectedLine + "] but was [" + actualLine + "]"
);
}
line++;
}
} catch (IOException ioException) {
throw new GradleException("Unable to read from file " + path, ioException);
}
}
private static void assertNoClassFile(File file) {
if (file.getName().endsWith(".class")) {
throw new GradleException("Detected class file in distribution ('" + file.getName() + "')");
}
}
private Object distTaskOutput(TaskProvider<Task> buildDistTask) {
return new Callable<File>() {
@Override
public File call() {
return buildDistTask.get().getOutputs().getFiles().getSingleFile();
}
@Override
public String toString() {View on GitHub (pinned to db6a809a66)
Solutions
- Verify the file at the reported path actually exists after checkExtraction — re-run the distribution build if incomplete.
- Check the path resolution logic in registerCheckNoticeTask/registerCheckLicenseTask for version-mismatch in 'elasticsearch-' + VersionProperties.getElasticsearch().
- Ensure checkExtraction depends on the build task and ran successfully.
- Inspect file permissions and encoding of the extracted file.
Example fix
// before: path resolves to non-existent elasticsearch-9.0.0/NOTICE.txt
// because VersionProperties.getElasticsearch() doesn't match archive name
// after: confirm the version string matches the archive directory name
String ver = VersionProperties.getElasticsearch();
Path notice = extractionDir.resolve("elasticsearch-" + ver + "/NOTICE.txt");
if (Files.exists(notice) == false) {
throw new IllegalStateException("NOTICE.txt missing; archive dir mismatch: " + notice);
} Defensive patterns
Strategy: validation
Validate before calling
Path p = noticePath.get();
if (Files.exists(p) == false) {
throw new IllegalStateException("File missing before check: " + p);
}
if (Files.isReadable(p) == false) {
throw new IllegalStateException("File not readable: " + p);
} Try / catch
try {
assertLinesInFile(path, expectedLines);
} catch (GradleException e) {
// includes IOException-wrapped message
throw e;
} Prevention
- Ensure checkExtraction completes successfully before checkLicense/checkNotice run (dependsOn).
- Verify the extracted archive contains NOTICE.txt and LICENSE.txt.
- Confirm VersionProperties.getElasticsearch() matches the archive's directory name.
- Run the full distribution build before the check tasks.
When it happens
Trigger: The try block at line 194 calls Files.readAllLines(path). If path doesn't exist, isn't readable, or contains malformed UTF-8, an IOException is thrown and wrapped at line 207. Typically fires when checkExtraction didn't extract the expected file (distribution build incomplete) or the path resolves incorrectly.
Common situations: The distribution archive was built incompletely (NOTICE.txt or LICENSE.txt missing from the archive); extraction directory was cleaned between build and check; path resolution bug in the noticePath/licensePathProvider mapping; file permissions on CI agent.
Related errors
- Cannot load VersionPropertiesBuildService
- Cannot resolve minimum compiler version via VersionPropertie
- unable to read the git revision
- Cannot read ${f} to check for duplicate license headers
- Cannot generate license header report for ${path}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/3985dee044b806bf.
Report an issue: GitHub.