{"record":{"id":"23fde7001fbc9038","repo":"elastic/elasticsearch","slug":"same-version-specified-to-add-and-remove","errorCode":null,"errorMessage":"Same version specified to add and remove","messagePattern":"Same version specified to add and remove","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/UpdateVersionsTask.java","lineNumber":97,"sourceCode":"    static Optional<Version> parseVersionField(CharSequence field) {\n        Matcher m = VERSION_FIELD.matcher(field);\n        if (m.find() == false) return Optional.empty();\n\n        return Optional.of(\n            new Version(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)), Integer.parseInt(m.group(3)), m.group(4))\n        );\n    }\n\n    @TaskAction\n    public void executeTask() throws IOException {\n        if (addVersion == null && removeVersion == null) {\n            throw new IllegalArgumentException(\"No versions to add or remove specified\");\n        }\n        if (setCurrent && addVersion == null) {\n            throw new IllegalArgumentException(\"No new version added to set as the current version\");\n        }\n        if (addVersion != null && removeVersion != null && Objects.equals(addVersion, removeVersion)) {\n            throw new IllegalArgumentException(\"Same version specified to add and remove\");\n        }\n\n        Path versionJava = rootDir.resolve(VERSION_FILE_PATH);\n        CompilationUnit file = LexicalPreservingPrinter.setup(StaticJavaParser.parse(versionJava));\n\n        Optional<CompilationUnit> modifiedFile = Optional.empty();\n        if (addVersion != null) {\n            LOGGER.lifecycle(\"Adding new version [{}] to [{}]\", addVersion, versionJava);\n            var added = addVersionConstant(modifiedFile.orElse(file), addVersion, setCurrent);\n            if (added.isPresent()) {\n                modifiedFile = added;\n            }\n        }\n        if (removeVersion != null) {\n            LOGGER.lifecycle(\"Removing version [{}] from [{}]\", removeVersion, versionJava);\n            var removed = removeVersionConstant(modifiedFile.orElse(file), removeVersion);\n            if (removed.isPresent()) {\n                modifiedFile = removed;","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/UpdateVersionsTask.java#L79-L115","documentation":"Thrown by UpdateVersionsTask.executeTask() when addVersion and removeVersion are both set and are equal. Adding and removing the same version in one run is contradictory and is rejected up front.","triggerScenarios":"Passing the same version string to both --add-version and --remove-version.","commonSituations":"A templated command reused the same variable for both options; a copy-paste error in the release command.","solutions":["Use distinct versions for --add-version and --remove-version.","If only one operation is intended, omit the other option."],"exampleFix":"// before\n./gradlew updateVersions --add-version=8.10.0 --remove-version=8.10.0\n\n// after\n./gradlew updateVersions --add-version=8.10.0 --remove-version=8.9.0","handlingStrategy":"validation","validationCode":"// Reject contradictory add/remove of the same version early\nString add = providers.gradleProperty(\"add-version\").getOrElse(null);\nString remove = providers.gradleProperty(\"remove-version\").getOrElse(null);\nif (add != null && add.equals(remove)) {\n    throw new GradleException(\"--add-version and --remove-version must differ\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not reuse a single version variable for both --add-version and --remove-version."],"tags":["release-tooling","gradle-task","option-conflict","precondition"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}