elastic/elasticsearch · error · UncheckedIOException
Failed to parse content of branches.json
Error message
Failed to parse content of branches.json
What it means
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.
Source
Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/BranchesFileParser.java:41
* A parser for the branches.json file
*/
public class BranchesFileParser {
private final ObjectMapper objectMapper;
public BranchesFileParser(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
public List<DevelopmentBranch> parse(byte[] bytes) {
List<DevelopmentBranch> branches = new ArrayList<>();
try {
JsonNode json = objectMapper.readTree(bytes);
for (JsonNode node : json.get("branches")) {
branches.add(new DevelopmentBranch(node.get("branch").asText(), Version.fromString(node.get("version").asText())));
}
} catch (IOException e) {
throw new UncheckedIOException("Failed to parse content of branches.json", e);
}
return branches;
}
}
View on GitHub (pinned to db6a809a66)
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.
Example fix
// before (malformed)
{
"branches": [
{ "branch": "main", "version": "9.0.0", }, // trailing comma
]
}
// after (valid)
{
"branches": [
{ "branch": "main", "version": "9.0.0" }
]
} Defensive patterns
Strategy: validation
Validate before calling
// Validate JSON before passing to parser
try {
new ObjectMapper().readTree(bytes);
} catch (IOException e) {
throw new IllegalArgumentException("branches.json is not valid JSON", e);
} Try / catch
try {
List<DevelopmentBranch> branches = new BranchesFileParser(objectMapper).parse(bytes);
} catch (UncheckedIOException e) {
// log and fall back to empty list or re-throw with context
logger.error("Failed to parse branches.json", e);
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to read branches.json from: {}
- expected data to start with an object
- Unexpected end of file
- ordered {} are not supported
- Failed to read {exclusionsFileAbsolutePath}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/74be3fe1accb4967.
Report an issue: GitHub.