{"record":{"id":"93fef7eb473c54ad","repo":"hibernate/hibernate-orm","slug":"can-t-find-ending-quote-of-key-name","errorCode":null,"errorMessage":"Can't find ending quote of key name","messagePattern":"Can't find ending quote of key name","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java","lineNumber":364,"sourceCode":"\t\treturn allGood?(this.jsonValueEnd-this.jsonValueStart):-1;\n\t}\n\t/**\n\t * Consumes a quoted value\n\t * @return the length of this value. can be 0, -1 in case of error\n\t */\n\tprivate void consumeQuotedString() {\n\n\t\t// be sure we are at a meaningful place\n\t\t// key name are unquoted\n\t\tmoveTo( StringJsonDocumentMarker.QUOTE.getMarkerCharacter() );\n\n\t\t// skip the quote we are positioned on.\n\t\tthis.position++;\n\n\t\t//locate ending quote\n\t\tint endingQuote = nextQuote();\n\t\tif (endingQuote == -1) {\n\t\t\tthrow new IllegalStateException(\"Can't find ending quote of key name\");\n\t\t}\n\n\t\tthis.jsonValueEnd = endingQuote;\n\t\tthis.jsonValueStart = position;\n\n\t\tthis.position =  endingQuote + 1;\n\n\t}\n\n\t/**\n\t * Ensures that the current state is on value.\n\t * @throws IllegalStateException if not on \"value\" state\n\t */\n\tprivate void ensureValueState() throws IllegalStateException {\n\t\tif ( (this.processingStates.getCurrent() != JsonProcessingState.OBJECT ) &&\n\t\t\tthis.processingStates.getCurrent() != JsonProcessingState.ARRAY)  {\n\t\t\tthrow new IllegalStateException( \"unexpected processing state: \" + this.processingStates.getCurrent() );\n\t\t}","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java#L346-L382","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"-- before: key literal never closed\nUPDATE entity_table SET json_col = '{\"key: 1}';\n-- after: properly terminated literal\nUPDATE entity_table SET json_col = '{\"key\": 1}';","handlingStrategy":"try-catch","validationCode":"static boolean allStringLiteralsClosed(String json) {\n    boolean inString = false;\n    for (int i = 0; i < json.length(); i++) {\n        char c = json.charAt(i);\n        if (inString && c == '\\\\') { i++; continue; }\n        if (c == '\"') inString = !inString;\n    }\n    return !inString;\n}","typeGuard":null,"tryCatchPattern":"try {\n    entity = session.find(MyEntity.class, id);\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Can't find ending quote\")) {\n        throw new DataQualityException(\"Unterminated string literal in JSON column\", e);\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["hibernate","json","parser","unterminated-string","malformed-data"],"backgroundTag":"json-parse-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}