quarkusio/quarkus · error · IllegalArgumentException

Unable to read json constant for: %s

Error message

Unable to read json constant for: %s

What it means

readConstant(expected, result) matches a literal keyword (true, false, null) at the current parser position. If the text at that position does not exactly equal the expected constant, it throws this IllegalArgumentException. It means the parser expected the JSON keyword `expected` but found different characters there.

Source

Thrown at core/builder/src/main/java/io/quarkus/builder/JsonReader.java:316

        return isFraction;
    }

    private void ignoreDigits() {
        while (position < length) {
            final int ch = peekChar();
            if (!Character.isDigit(ch)) {
                break;
            }
            position++;
        }
    }

    private JsonValue readConstant(String expected, JsonValue result) {
        if (text.regionMatches(position, expected, 0, expected.length())) {
            position += expected.length();
            return result;
        }
        throw new IllegalArgumentException("Unable to read json constant for: " + expected);
    }

    /**
     * ws
     * |---- ""
     * |---- '0020' ws
     * |---- '000A' ws
     * |---- '000D' ws
     * |---- '0009' ws
     */
    private void ignoreWhitespace() {
        while (position < length) {
            final int ch = peekChar();
            switch (ch) {
                case ' ': // '0020' SPACE
                case '\n': // '000A' LINE FEED
                case '\r': // '000D' CARRIAGE RETURN
                case '\t': // '0009' CHARACTER TABULATION

View on GitHub (pinned to e1c734241f)

Solutions

  1. Use the exact lowercase JSON keywords: true, false, null (not True, TRUE, nil, None).
  2. Inspect the input at the reported position and correct or complete the misspelled keyword.
  3. Validate the JSON with a standard parser to find all malformed values at once.
  4. Fix any template/generation step that emits placeholders or truncated output where the keyword belongs.

Example fix

// before
String json = "{\"flag\":True}"; // not a JSON keyword

// after
String json = "{\"flag\":true}";
Defensive patterns

Strategy: validation

Validate before calling

// ensure only exact lowercase JSON keywords are used
boolean hasValidConstants(String json) {
    return !json.matches("(?i).*[^\\\"]?(True|False|TRUE|FALSE|None|nil|NULL)[^\\\"]?.*")
        || json.matches(".*\\b(true|false|null)\\b.*");
}
// simpler: pre-validate with a standard JSON parser before JsonReader

Try / catch

try {
    JsonReader.parse(json);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Unable to read json constant")) {
        throw new ConfigException("Invalid JSON keyword; only lowercase true/false/null are accepted", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Parsing JSON where a value position contains a misspelled or truncated keyword, e.g. "tru", "falsee", "nil", or an identifier like "True"/"NULL" instead of the exact lowercase true/false/null that readValue dispatched to readConstant.

Common situations: Hand-written JSON with casing mistakes (True, FALSE) borrowed from other languages; templated JSON with an unfilled placeholder where the keyword should be; truncated documents cutting a keyword short; typos in generated JSON.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/9b17f6f0da9242ab. Report an issue: GitHub.