elastic/elasticsearch · error · GradleException

Failed to load keywords JSON from {jsonKeywords} - {message}

Error message

Failed to load keywords JSON from {jsonKeywords} - {message}

What it means

Thrown by ValidateJsonNoKeywordsTask when parsing the keywords JSON file (jsonKeywords) with Jackson raises an IOException. The mapper.readTree call expects a JSON object mapping language -> array of keyword strings; any malformed JSON, I/O error, or unexpected structure surfaces here with the offending file name and parse error message.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ValidateJsonNoKeywordsTask.java:227

     * multiple languages, so it is easier and more useful to have a single map of keywords.
     *
     * @return a mapping from keyword to languages.
     */
    private Map<String, Set<String>> loadKeywords(ObjectMapper mapper) {
        Map<String, Set<String>> languagesByKeyword = new HashMap<>();

        try {
            final ObjectNode keywordsNode = ((ObjectNode) mapper.readTree(this.jsonKeywords));

            keywordsNode.fieldNames().forEachRemaining(eachLanguage -> {
                keywordsNode.get(eachLanguage).elements().forEachRemaining(e -> {
                    final String eachKeyword = e.textValue();
                    final Set<String> languages = languagesByKeyword.computeIfAbsent(eachKeyword, _keyword -> new HashSet<>());
                    languages.add(eachLanguage);
                });
            });
        } catch (IOException e) {
            throw new GradleException("Failed to load keywords JSON from " + jsonKeywords.getName() + " - " + e.getMessage(), e);
        }

        return languagesByKeyword;
    }
}

View on GitHub (pinned to db6a809a66)

Solutions

  1. Open the named jsonKeywords file and fix the JSON syntax error indicated by the attached IOException message.
  2. Validate the file with a JSON linter (e.g. jq . <file>) before re-running.
  3. If the file was corrupted by a merge conflict, resolve the conflict and re-validate.
  4. Re-run :<project>:validateJsonNoKeywords.

Example fix

// before (invalid JSON)
{
  "en": ["select", "from",]
}
// after (trailing comma removed)
{
  "en": ["select", "from"]
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate JSON syntax before the task parses it
try (JsonParser p = jsonMapper.getFactory().createParser(jsonKeywordsFile)) {
    while (p.nextToken() != null) { /* drain */ }
} catch (IOException e) {
    throw new IllegalStateException("Keywords JSON is malformed: " + e.getMessage());
}

Try / catch

try { Map<String,Set<String>> kw = loadKeywords(jsonKeywordsFile); }
catch (GradleException e) { /* message names file + parse error — fix the JSON, don't ignore */ throw e; }

Prevention

When it happens

Trigger: The getJsonKeywords() file is opened and parsed into an ObjectNode; a syntax error (trailing comma, unquoted key, truncated file) or a read failure causes Jackson to throw IOException, caught and rethrown as a GradleException naming the file and the parse error.

Common situations: Hand-editing the keywords JSON and introducing a syntax error; a merge conflict artifact left inside the file; file truncated by an interrupted write; the file is valid JSON but not a JSON object (e.g. an array), causing the ObjectNode cast downstream to fail (separate failure) — but this specific throw is for parse IOException.

Related errors


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