elastic/elasticsearch · error · GradleException

expected line [${line + 1}] in [${path}] to be [${expectedLi

Error message

expected line [${line + 1}] in [${path}] to be [${expectedLine}] but was [${actualLine}]

What it means

Thrown as GradleException by assertLinesInFile() when a line in the file at a given position doesn't exactly equal the expected line. Unlike the NOTICE 'contains' check, this asserts ordered, line-by-line equality starting from line 1 — used for NOTICE.txt header ('Elasticsearch', 'Copyright 2009-2024 Elasticsearch') and LICENSE.txt content where exact prefix ordering matters.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveCheckPlugin.java:200

            if (project.getName().contains("tar")) {
                t.from(archiveOperations.tarTree(distTaskOutput(buildDistTask)));
            } else {
                t.from(archiveOperations.zipTree(distTaskOutput(buildDistTask)));
            }
            t.into(archiveExtractionDir);
            // common sanity checks on extracted archive directly as part of checkExtraction
            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>() {

View on GitHub (pinned to db6a809a66)

Solutions

  1. Read the error's expected vs actual strings — usually a year, version, or whitespace difference.
  2. Update the expected lines in registerCheckNoticeTask (the 'Elasticsearch' / copyright line) or the source LICENSE.txt template to match actual content.
  3. Regenerate the license file from source with the licensing plugin before running check.
  4. Ensure line endings are consistent (LF) — Files.readAllLines uses UTF-8 and splits on LF/CRLF, but mixed endings can shift content.

Example fix

// before: hardcoded copyright year is stale
final List<String> noticeLines = Arrays.asList("Elasticsearch", "Copyright 2009-2024 Elasticsearch");

// after: keep the year in sync with the build
final List<String> noticeLines = Arrays.asList("Elasticsearch", "Copyright 2009-" + Year.now() + " Elasticsearch");
Defensive patterns

Strategy: validation

Validate before calling

List<String> actual = Files.readAllLines(path);
if (actual.size() < expectedLines.size()
    || IntStream.range(0, expectedLines.size())
        .anyMatch(i -> expectedLines.get(i).equals(actual.get(i)) == false)) {
    System.err.println("Line mismatch in " + path);
}

Prevention

When it happens

Trigger: assertLinesInFile (line 193) reads all lines, then iterates expectedLines comparing actualLines.get(line) with expectedLine. The first mismatch throws with 1-based line number, path, expected, and actual. Called from checkNotice (NOTICE.txt header) and checkLicense (LICENSE.txt full content).

Common situations: Copyright year bumped (e.g., 2024 → 2025) but the expected line wasn't updated; license file regenerated with different whitespace or line endings; a new top-of-file line shifted all subsequent lines; LICENSE.txt template changed upstream.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/f613b9a748ad05e1. Report an issue: GitHub.