{"record":{"id":"37af84a3d103d984","repo":"hibernate/hibernate-orm","slug":"unexpected-read-in-current-processing-state","errorCode":null,"errorMessage":"unexpected read [{}] in current processing state {}","messagePattern":"unexpected read \\[(.+?)\\] in current processing state (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java","lineNumber":218,"sourceCode":"\t\t\t\tcase SEPARATOR:\n\t\t\t\t\t// unless we are processing an array, following SEPARATOR that will a key\n\t\t\t\t\tbreak;\n\t\t\t\tcase OTHER:\n\t\t\t\t\t// here we are in front of a boolean, a null or a numeric value.\n\t\t\t\t\t// if none of these cases we're going to raise IllegalStateException\n\t\t\t\t\t// put back what we've read\n\t\t\t\t\tmoveBufferPosition(-1);\n\t\t\t\t\tfinal int valueSize = consumeNonStringValue();\n\t\t\t\t\tif (valueSize == -1) {\n\t\t\t\t\t\tthrow new IllegalStateException( \"Unrecognized marker: \" + StringJsonDocumentMarker.markerOf(\n\t\t\t\t\t\t\t\tthis.jsonString.charAt( this.position )));\n\t\t\t\t\t}\n\t\t\t\t\tswitch ( this.processingStates.getCurrent() ) {\n\t\t\t\t\t\tcase ARRAY:\n\t\t\t\t\t\tcase OBJECT:\n\t\t\t\t\t\t\treturn getUnquotedValueType(this.jsonString.charAt( this.jsonValueStart));\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthrow new IllegalStateException( \"unexpected read [\"+\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.jsonString.substring( this.jsonValueStart,this.jsonValueEnd )+\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"] in current processing state \" +\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.processingStates.getCurrent() );\n\t\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new IllegalStateException( \"unexpected marker [\"+\n\t\t\t\t\t\t\t\t\t\t\t\t\tmarker +\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"] at position \" + this.position );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalStateException( \"unexpected end of JSON [\"+\n\t\t\t\t\t\t\t\t\t\tthis.jsonString.substring( this.jsonValueStart,this.jsonValueEnd )+\n\t\t\t\t\t\t\t\t\t\t\"] in current processing state \" +\n\t\t\t\t\t\t\t\t\t\tthis.processingStates.getCurrent() );\n\t}\n\n\t/**","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java#L200-L236","documentation":"An unquoted token was consumed successfully, but the state machine is neither ARRAY nor OBJECT — bare literals are only legal as array elements or as an object attribute value after ':'. The message shows the token and state, e.g. 'unexpected read [a] in current processing state STARTING_OBJECT'. The two classic causes are unquoted object keys and top-level bare scalars.","triggerScenarios":"next() reading an OTHER token while state is STARTING_OBJECT (unquoted key like {a:1} — JSON requires keys in quotes), NONE (bare top-level scalar document like 42 or true), or OBJECT_KEY_NAME/ENDING_* states where a quoted key or structural token is required.","commonSituations":"Hand-written 'relaxed JSON' with unquoted keys or single quotes (JavaScript object literals) pasted into a column; systems emitting non-strict JSON; storing a plain number/string directly in a JSON column without wrapping it in an object or array.","solutions":["Fix the stored document to strict JSON: quoted keys ({\"a\":1}) and object/array roots","Make the producing system emit strict JSON (use a serializer, not string concatenation)","Pre-validate on write with a strict parser","Catch IllegalStateException around reads to identify and migrate offending rows"],"exampleFix":"-- before: unquoted key (JavaScript-style object literal)\nUPDATE entity_table SET json_col = '{name:\"Ada\"}';\n-- after: strict JSON\nUPDATE entity_table SET json_col = '{\"name\":\"Ada\"}';","handlingStrategy":"validation","validationCode":"static void assertStrictJsonObject(String candidate) {\n    com.fasterxml.jackson.databind.ObjectMapper m =\n            new com.fasterxml.jackson.databind.ObjectMapper()\n                    .enable(com.fasterxml.jackson.core.JsonParser.Feature.STRICT_DUPLICATE_DETECTION);\n    try {\n        m.readTree(candidate);\n    } catch (Exception e) {\n        throw new IllegalArgumentException(\"Not strict JSON (unquoted keys? bare scalar root?): \" + e.getMessage(), e);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    entity = session.find(MyEntity.class, id);\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"unexpected read [\")) {\n        // stored document uses relaxed JSON (e.g. unquoted keys) - repair required\n        throw new DataQualityException(\"Column contains non-strict JSON\", e);\n    }\n    throw e;\n}","preventionTips":["Never build JSON with string concatenation; use a serializer","Reject JavaScript-style literals (single quotes, unquoted keys) at the API boundary","Wrap bare scalar values in an object or array before storing them in JSON columns"],"tags":["hibernate","json","parser","state-machine","malformed-data"],"backgroundTag":"json-parse-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}