{"record":{"id":"99b6255fb1dd5e8a","repo":"elastic/elasticsearch","slug":"cannot-remove-version-s-it-is-referenced-by-cu","errorCode":null,"errorMessage":"Cannot remove version [%s], it is referenced by CURRENT","messagePattern":"Cannot remove version \\[(.+?)\\], it is referenced by CURRENT","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/UpdateVersionsTask.java","lineNumber":195,"sourceCode":"        String removeFieldName = toVersionField(version);\n\n        ClassOrInterfaceDeclaration versionClass = versionJava.getClassByName(\"Version\").get();\n        var declaration = versionClass.getFieldByName(removeFieldName);\n        if (declaration.isEmpty()) {\n            LOGGER.lifecycle(\"Version constant [{}] not found, skipping\", removeFieldName);\n            return Optional.empty();\n        }\n\n        // check if this is referenced by CURRENT\n        String currentReference = versionClass.getFieldByName(\"CURRENT\")\n            .orElseThrow(() -> new IllegalArgumentException(\"Could not find CURRENT constant\"))\n            .getVariable(0)\n            .getInitializer()\n            .get()\n            .asNameExpr()\n            .getNameAsString();\n        if (currentReference.equals(removeFieldName)) {\n            throw new IllegalArgumentException(String.format(\"Cannot remove version [%s], it is referenced by CURRENT\", version));\n        }\n\n        declaration.get().remove();\n\n        return Optional.of(versionJava);\n    }\n}\n","sourceCodeStart":177,"sourceCodeEnd":203,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/UpdateVersionsTask.java#L177-L203","documentation":"Thrown in UpdateVersionsTask.removeVersion() when the constant slated for removal is the one CURRENT points at. Removing it would leave CURRENT dangling, so the operation is refused.","triggerScenarios":"Passing --remove-version=<X> where the CURRENT initializer in Version.java references the constant for X.","commonSituations":"A release step tries to remove the currently-active version constant without first repointing CURRENT; the wrong version was selected for removal.","solutions":["First add the new version with --add-version=<new> --set-current, commit, then remove the old version in a separate step.","If CURRENT is wrong, update it to a different constant before removing the target.","Double-check that the version being removed is not the live one."],"exampleFix":"// before\n./gradlew updateVersions --remove-version=8.10.0   # CURRENT points at V_8_10_0\n\n// after\n./gradlew updateVersions --add-version=8.11.0 --set-current\n# (commit, then later)\n./gradlew updateVersions --remove-version=8.10.0","handlingStrategy":"validation","validationCode":"// Determine which constant CURRENT references and refuse to remove it\nString currentRef = /* parse the initializer of CURRENT in Version.java */;\nString removeConst = \"V_\" + removeVersion.getMajor() + \"_\" + String.format(\"%02d\", removeVersion.getMinor()) + \"_\" + String.format(\"%02d\", removeVersion.getRevision()) + \"_99\";\nif (currentRef.equals(removeConst)) {\n    throw new GradleException(\"Cannot remove \" + removeVersion + \"; repoint CURRENT first via --add-version + --set-current\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sequence removals after a CURRENT repoint: add new + set-current, commit, then remove old.","Never remove the version that CURRENT points at directly."],"tags":["release-tooling","version-constants","current-reference","data-integrity","precondition"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}