elastic/elasticsearch · error · IllegalArgumentException

Cannot remove version [%s], it is referenced by CURRENT

Error message

Cannot remove version [%s], it is referenced by CURRENT

What it means

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.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/UpdateVersionsTask.java:195

        String removeFieldName = toVersionField(version);

        ClassOrInterfaceDeclaration versionClass = versionJava.getClassByName("Version").get();
        var declaration = versionClass.getFieldByName(removeFieldName);
        if (declaration.isEmpty()) {
            LOGGER.lifecycle("Version constant [{}] not found, skipping", removeFieldName);
            return Optional.empty();
        }

        // check if this is referenced by CURRENT
        String currentReference = versionClass.getFieldByName("CURRENT")
            .orElseThrow(() -> new IllegalArgumentException("Could not find CURRENT constant"))
            .getVariable(0)
            .getInitializer()
            .get()
            .asNameExpr()
            .getNameAsString();
        if (currentReference.equals(removeFieldName)) {
            throw new IllegalArgumentException(String.format("Cannot remove version [%s], it is referenced by CURRENT", version));
        }

        declaration.get().remove();

        return Optional.of(versionJava);
    }
}

View on GitHub (pinned to db6a809a66)

Solutions

  1. First add the new version with --add-version=<new> --set-current, commit, then remove the old version in a separate step.
  2. If CURRENT is wrong, update it to a different constant before removing the target.
  3. Double-check that the version being removed is not the live one.

Example fix

// before
./gradlew updateVersions --remove-version=8.10.0   # CURRENT points at V_8_10_0

// after
./gradlew updateVersions --add-version=8.11.0 --set-current
# (commit, then later)
./gradlew updateVersions --remove-version=8.10.0
Defensive patterns

Strategy: validation

Validate before calling

// Determine which constant CURRENT references and refuse to remove it
String currentRef = /* parse the initializer of CURRENT in Version.java */;
String removeConst = "V_" + removeVersion.getMajor() + "_" + String.format("%02d", removeVersion.getMinor()) + "_" + String.format("%02d", removeVersion.getRevision()) + "_99";
if (currentRef.equals(removeConst)) {
    throw new GradleException("Cannot remove " + removeVersion + "; repoint CURRENT first via --add-version + --set-current");
}

Prevention

When it happens

Trigger: Passing --remove-version=<X> where the CURRENT initializer in Version.java references the constant for X.

Common situations: A release step tries to remove the currently-active version constant without first repointing CURRENT; the wrong version was selected for removal.

Related errors


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