{"record":{"id":"1595c87cd19a987a","repo":"elastic/elasticsearch","slug":"we-should-be-comparing-different-jars-but-origina","errorCode":null,"errorMessage":"We should be comparing different jars, but original and new jars were both: ${newJarFile.getAbsolutePath()}","messagePattern":"We should be comparing different jars, but original and new jars were both: (.+?)","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/JarApiComparisonTask.java","lineNumber":75,"sourceCode":" *     an API.</li>\n *     <li>Finally, moving a method up the class hierarchy is not really a breaking change,\n *     but it will trip this test.</li>\n * </ol>\n */\n@CacheableTask\npublic abstract class JarApiComparisonTask extends PrecommitTask {\n\n    @TaskAction\n    public void compare() {\n        FileCollection fileCollection = getOldJar().get();\n        File newJarFile = getNewJar().get().getSingleFile();\n\n        Set<String> oldJarNames = fileCollection.getFiles().stream().map(File::getName).collect(Collectors.toSet());\n        if (oldJarNames.size() > 1) {\n            throw new IllegalStateException(\"Expected a single original jar, but found: \" + oldJarNames);\n        }\n        if (oldJarNames.contains(newJarFile.getName())) {\n            throw new IllegalStateException(\n                \"We should be comparing different jars, but original and new jars were both: \" + newJarFile.getAbsolutePath()\n            );\n        }\n\n        JarScanner oldJS = new JarScanner(getOldJar().get().getSingleFile().getPath());\n        JarScanner newJS = new JarScanner(newJarFile.getPath());\n        try {\n            JarScanner.compareSignatures(oldJS.jarSignature(), newJS.jarSignature());\n        } catch (IOException e) {\n            throw new RuntimeException(e);\n        }\n    }\n\n    @CompileClasspath\n    public abstract Property<FileCollection> getOldJar();\n\n    @CompileClasspath\n    public abstract Property<FileCollection> getNewJar();","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/JarApiComparisonTask.java#L57-L93","documentation":"Thrown as IllegalStateException in JarApiComparisonTask.compare() when the oldJar and newJar have the same filename. Comparing a jar against itself (or two jars with identical names) is a no-op that would always pass and mask real API changes; the guard refuses to run a meaningless comparison. This typically indicates the old and new configurations resolve to the same artifact.","triggerScenarios":"At line 74, oldJarNames.contains(newJarFile.getName()) is checked. If the new jar's filename matches the (single) old jar's filename, the exception fires with the new jar's absolute path. Triggered when both properties point to the same file, or when version-stripped names collide.","commonSituations":"The oldJar and newJar configurations both resolve the current version's jar (BWC version not actually different); a copy-paste error wiring both properties to the same configuration; the BWC old-version download failed and fell back to the current jar; version classifiers are missing so both resolve to 'elasticsearch-server-9.0.0.jar'.","solutions":["Verify getOldJar() resolves to a genuinely different (older) version's jar — check the BWC version string and dependency coordinates.","Ensure the old-version download/build actually produced a distinct file (different version in the filename).","Inspect newJarFile.getAbsolutePath() in the error and confirm getOldJar() doesn't resolve the same path.","If comparing against a baseline jar with the same name, place them in different directories and disambiguate, or rename."],"exampleFix":"// before: both resolve current version\ngetOldJar().from(configurations.named(\"runtimeClasspath\"))\ngetNewJar().from(tasks.named(\"jar\"))\n// both named elasticsearch-server-9.0.0.jar → throws\n\n// after: oldJar resolves the previous BWC version\ngetOldJar().from(configurations.named(\"bwcPrevApiJar\"))  // elasticsearch-server-8.x.jar\ngetNewJar().from(tasks.named(\"jar\"))                    // elasticsearch-server-9.0.0.jar","handlingStrategy":"validation","validationCode":"String newName = getNewJar().get().getSingleFile().getName();\nSet<String> oldNames = getOldJar().get().getFiles().stream().map(File::getName).collect(Collectors.toSet());\nif (oldNames.contains(newName)) {\n    throw new IllegalStateException(\"old and new jars have the same name: \" + newName + \" — versions not distinct?\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure getOldJar() resolves a genuinely different version than getNewJar().","Verify BWC old-version downloads/builds produce distinct filenames (version in name).","Check that version classifiers aren't stripped from artifact names.","Inspect both absolute paths when this fires to confirm the version mismatch."],"tags":["api-comparison","bwc","configuration","validation"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}