{"record":{"id":"74be3fe1accb4967","repo":"elastic/elasticsearch","slug":"failed-to-parse-content-of-branches-json","errorCode":null,"errorMessage":"Failed to parse content of branches.json","messagePattern":"Failed to parse content of branches\\.json","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/BranchesFileParser.java","lineNumber":41,"sourceCode":" * A parser for the branches.json file\n */\npublic class BranchesFileParser {\n\n    private final ObjectMapper objectMapper;\n\n    public BranchesFileParser(ObjectMapper objectMapper) {\n        this.objectMapper = objectMapper;\n    }\n\n    public List<DevelopmentBranch> parse(byte[] bytes) {\n        List<DevelopmentBranch> branches = new ArrayList<>();\n        try {\n            JsonNode json = objectMapper.readTree(bytes);\n            for (JsonNode node : json.get(\"branches\")) {\n                branches.add(new DevelopmentBranch(node.get(\"branch\").asText(), Version.fromString(node.get(\"version\").asText())));\n            }\n        } catch (IOException e) {\n            throw new UncheckedIOException(\"Failed to parse content of branches.json\", e);\n        }\n\n        return branches;\n    }\n}\n","sourceCodeStart":23,"sourceCodeEnd":47,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/BranchesFileParser.java#L23-L47","documentation":"Thrown by BranchesFileParser.parse(byte[]) when Jackson's ObjectMapper.readTree(bytes) throws IOException, or when iterating the JSON tree fails. The parser reads a 'branches' array, extracting 'branch' and 'version' fields for each DevelopmentBranch. The IOException is wrapped in UncheckedIOException. Note: structural issues like missing 'branches' key would throw NullPointerException (not caught here), while malformed JSON triggers this IOException path.","triggerScenarios":"branches.json contains malformed JSON (syntax error), truncated content, or an encoding issue that prevents Jackson from parsing. The ObjectMapper is constructed with default settings, so duplicate keys or trailing content could also cause parse failures depending on Jackson configuration.","commonSituations":"branches.json was partially downloaded (network truncation) or manually edited with a syntax error. The file has a BOM (byte order mark) or non-UTF-8 encoding that confuses the parser. A CI cache served a stale or corrupted copy of the file.","solutions":["Validate branches.json with a JSON linter: cat branches.json | python3 -m json.tool.","If downloaded, re-download from the source URL to get a clean copy.","If editing manually, ensure proper JSON syntax (no trailing commas, quoted keys).","Check for encoding issues: file -i branches.json should report charset=utf-8."],"exampleFix":"// before (malformed)\n{\n  \"branches\": [\n    { \"branch\": \"main\", \"version\": \"9.0.0\", }, // trailing comma\n  ]\n}\n\n// after (valid)\n{\n  \"branches\": [\n    { \"branch\": \"main\", \"version\": \"9.0.0\" }\n  ]\n}","handlingStrategy":"validation","validationCode":"// Validate JSON before passing to parser\ntry {\n    new ObjectMapper().readTree(bytes);\n} catch (IOException e) {\n    throw new IllegalArgumentException(\"branches.json is not valid JSON\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    List<DevelopmentBranch> branches = new BranchesFileParser(objectMapper).parse(bytes);\n} catch (UncheckedIOException e) {\n    // log and fall back to empty list or re-throw with context\n    logger.error(\"Failed to parse branches.json\", e);\n    throw e;\n}","preventionTips":["Validate branches.json with a JSON linter after manual edits.","Use schema validation (e.g., json-schema-validator) to catch structural issues early.","Cache a known-good copy of branches.json for CI reproducibility."],"tags":["json","parsing","configuration","branches","io"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}