hibernate/hibernate-orm · error · IllegalStateException
Can't find ending quote of key name
Error message
Can't find ending quote of key name
What it means
consumeQuotedString() asks nextQuote() to find the closing '"' of a string literal; nextQuote() scans to the end of input and returns -1 when no unescaped closing quote exists (a backslash makes it skip the following character, so a literal ending in a lone '\' also never terminates). The reader therefore cannot delimit the string/key and throws — the JSON contains an unterminated string literal.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java:364
return allGood?(this.jsonValueEnd-this.jsonValueStart):-1;
}
/**
* Consumes a quoted value
* @return the length of this value. can be 0, -1 in case of error
*/
private void consumeQuotedString() {
// be sure we are at a meaningful place
// key name are unquoted
moveTo( StringJsonDocumentMarker.QUOTE.getMarkerCharacter() );
// skip the quote we are positioned on.
this.position++;
//locate ending quote
int endingQuote = nextQuote();
if (endingQuote == -1) {
throw new IllegalStateException("Can't find ending quote of key name");
}
this.jsonValueEnd = endingQuote;
this.jsonValueStart = position;
this.position = endingQuote + 1;
}
/**
* Ensures that the current state is on value.
* @throws IllegalStateException if not on "value" state
*/
private void ensureValueState() throws IllegalStateException {
if ( (this.processingStates.getCurrent() != JsonProcessingState.OBJECT ) &&
this.processingStates.getCurrent() != JsonProcessingState.ARRAY) {
throw new IllegalStateException( "unexpected processing state: " + this.processingStates.getCurrent() );
}View on GitHub (pinned to fad1729dce)
Solutions
- Repair the value: terminate the string literal, honoring escape rules
- Fix the producer to use a real JSON serializer instead of concatenation
- Validate on write with a strict parser
- Catch IllegalStateException to quarantine affected rows
Example fix
-- before: key literal never closed
UPDATE entity_table SET json_col = '{"key: 1}';
-- after: properly terminated literal
UPDATE entity_table SET json_col = '{"key": 1}'; Defensive patterns
Strategy: try-catch
Validate before calling
static boolean allStringLiteralsClosed(String json) {
boolean inString = false;
for (int i = 0; i < json.length(); i++) {
char c = json.charAt(i);
if (inString && c == '\\') { i++; continue; }
if (c == '"') inString = !inString;
}
return !inString;
} Try / catch
try {
entity = session.find(MyEntity.class, id);
} catch (IllegalStateException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Can't find ending quote")) {
throw new DataQualityException("Unterminated string literal in JSON column", e);
}
throw e;
} Prevention
- Generate JSON only through a serializer so quotes and escapes are always balanced
- Validate payloads with a strict parser at the write path
- Beware truncation when columns have length limits - unterminated strings are its most common symptom
When it happens
Trigger: Values like {"key: 1} (closing quote missing around the key), "abc\ (token ends with a bare escape character at end of input), or any string/key truncated mid-literal at the end of the column value.
Common situations: Truncated JSON columns; hand-edited values; writers that build JSON via string concatenation and forget the closing quote; data where an escape sequence was cut in half by truncation.
Related errors
- unexpected quote read in current processing state {}
- Unrecognized marker: {}
- unexpected read [{}] in current processing state {}
- unexpected end of JSON [{}] in current processing state {}
- Expected JSON object end, but none found.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/93fef7eb473c54ad.
Report an issue: GitHub.