{"record":{"id":"e326a68a3535ac1c","repo":"elastic/elasticsearch","slug":"branch-branch-already-exists","errorCode":null,"errorMessage":"Branch {branch} already exists","messagePattern":"Branch (.+?) already exists","errorType":"validation","errorClass":"InvalidUserDataException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/UpdateBranchesJsonTask.java","lineNumber":127,"sourceCode":"        String[] parts = branchAndVersion.split(\":\");\n        if (parts.length != 2) {\n            throw new InvalidUserDataException(\"Expected branch and version in format <branch>:<version>\");\n        }\n        return new DevelopmentBranch(parts[0], Version.fromString(parts[1]));\n    }\n\n    @TaskAction\n    public void executeTask() throws IOException {\n        List<DevelopmentBranch> developmentBranches = readBranches(branchesFile);\n\n        if (addBranch == null && removeBranch == null && updateBranch == null) {\n            throw new InvalidUserDataException(\"At least one of add-branch, remove-branch or update-branch must be specified\");\n        }\n\n        if (addBranch != null) {\n            LOGGER.info(\"Adding branch {} with version {}\", addBranch.name(), addBranch.version());\n            if (developmentBranches.stream().anyMatch(developmentBranch -> developmentBranch.name().equals(addBranch.name()))) {\n                throw new InvalidUserDataException(\"Branch \" + addBranch.name() + \" already exists\");\n            }\n            developmentBranches.add(addBranch);\n        }\n        if (removeBranch != null) {\n            LOGGER.info(\"Removing branch {}\", removeBranch);\n            if (developmentBranches.stream().noneMatch(developmentBranch -> developmentBranch.name().equals(removeBranch))) {\n                throw new InvalidUserDataException(\"Branch \" + removeBranch + \" does not exist\");\n            }\n            developmentBranches.removeIf(developmentBranch -> developmentBranch.name().equals(removeBranch));\n        }\n        if (updateBranch != null) {\n            LOGGER.info(\"Updating branch {} with version {}\", updateBranch.name(), updateBranch.version());\n            if (developmentBranches.stream().noneMatch(developmentBranch -> developmentBranch.name().equals(updateBranch.name()))) {\n                throw new InvalidUserDataException(\"Branch \" + updateBranch.name() + \" does not exist\");\n            }\n            developmentBranches.removeIf(developmentBranch -> developmentBranch.name().equals(updateBranch.name()));\n            developmentBranches.add(updateBranch);\n        }","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/UpdateBranchesJsonTask.java#L109-L145","documentation":"Thrown by UpdateBranchesJsonTask.executeTask() in the addBranch path when a branch with the same name already exists in branches.json. Addition is rejected to avoid duplicate entries.","triggerScenarios":"Running --add-branch=<name>:<version> for a branch name that is already listed in branches.json.","commonSituations":"Re-running an add step that partially completed; the branch was created by another process; an operator did not realise the branch already existed.","solutions":["If you intended to change the version of an existing branch, use --update-branch=<name>:<version> instead of --add-branch.","If the existing entry is wrong, first --remove-branch=<name>, then --add-branch.","Verify the current contents of branches.json before adding."],"exampleFix":"// before\n./gradlew updateBranches --add-branch=8.10:8.10.1   # 8.10 already present\n\n// after\n./gradlew updateBranches --update-branch=8.10:8.10.1","handlingStrategy":"validation","validationCode":"// Read branches.json and check for an existing branch before adding\nstatic boolean branchExists(Path branchesFile, String name) throws IOException {\n    return new ObjectMapper().readTree(branchesFile.toFile())\n        .path(\"branches\").findValuesAsText(\"branch\").contains(name);\n}\n// only call --add-branch when branchExists(...) is false","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer --update-branch when the branch may already exist.","Print the current branch list before adding."],"tags":["release-tooling","gradle-task","duplicate","branches-json"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}