{"record":{"id":"3a1d731d83e7214d","repo":"hibernate/hibernate-orm","slug":"unexpected-jsonprocessingstate","errorCode":null,"errorMessage":"Unexpected JsonProcessingState {}","messagePattern":"Unexpected JsonProcessingState (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java","lineNumber":131,"sourceCode":"\t\t\t\tthis.processingStates.pop();\n\t\t\t\tassert this.processingStates.getCurrent() == JsonProcessingState.OBJECT;\n\t\t\t\tbreak;\n\t\t\tcase QUOTE:\n\t\t\t\tif (currentState == JsonProcessingState.STARTING_ARRAY) {\n\t\t\t\t\tthis.processingStates.push( JsonProcessingState.ARRAY );\n\t\t\t\t}\n\t\t\t\tif (currentState == JsonProcessingState.STARTING_OBJECT) {\n\t\t\t\t\tthis.processingStates.push( JsonProcessingState.OBJECT );\n\t\t\t\t\tthis.processingStates.push( JsonProcessingState.OBJECT_KEY_NAME );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase OTHER:\n\t\t\t\tif ( currentState == JsonProcessingState.STARTING_ARRAY) {\n\t\t\t\t\tthis.processingStates.push( JsonProcessingState.ARRAY );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new IllegalStateException( \"Unexpected JsonProcessingState \" + marker );\n\t\t}\n\t}\n\n\t/**\n\t * Returns the next item.\n\t * @return the item\n\t * @throws NoSuchElementException no more item available\n\t * @throws IllegalStateException not a well-formed JSON string.\n\t */\n\t@Override\n\tpublic JsonDocumentItemType next() {\n\n\t\tif ( !hasNext()) throw new NoSuchElementException(\"no more elements\");\n\n\t\twhile (hasNext()) {\n\t\t\tskipWhiteSpace();\n\t\t\tStringJsonDocumentMarker marker = StringJsonDocumentMarker.markerOf( this.jsonString.charAt( this.position++ ) );\n\t\t\tmoveStateMachine( marker );","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java#L113-L149","documentation":"StringJsonDocumentReader is a pushdown-automaton JSON parser; moveStateMachine switches on the marker just read ({ } [ ] , \" : or OTHER, from StringJsonDocumentMarker.markerOf). The default branch throwing IllegalStateException 'Unexpected JsonProcessingState ' + marker is a defensive invariant: with the current marker set every character maps to a known marker, so in practice this branch indicates a parser bug or a marker enum extended without updating the state machine. Ordinary malformed JSON usually fails via the reader's other IllegalStateExceptions or asserts instead.","triggerScenarios":"Feeding a malformed or adversarial JSON document that drives the state machine down an unhandled marker path, or hitting a genuine bug in this (relatively new) string-based reader - e.g. after a Hibernate upgrade changed the marker/processing-state set.","commonSituations":"Corrupt or hand-edited JSON column data; documents produced by other generators; early adoption of Hibernate's string JSON reader where parser bugs surface; JVMs with assertions enabled changing which invariant fires first.","solutions":["Validate the stored document with a standard JSON parser (Jackson/Gson/JSON-P) before or in addition to Hibernate's reader, and repair bad rows","Upgrade (or, for a regression, roll back) Hibernate ORM - this parser is actively fixed","Capture the exact failing payload and report a Hibernate issue with the mapping and document"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-validate documents from untrusted sources before they reach Hibernate's reader\ncom.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();\ntry { om.readTree(json); } catch (Exception e) { reject(\"not well-formed JSON\", e); }","typeGuard":null,"tryCatchPattern":"try {\n    MyAgg agg = session.find(MyEntity.class, id).getAgg();\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unexpected JsonProcessingState\")) {\n        // parser invariant broken: capture payload, report upstream\n        LOG.error(\"Hibernate string JSON reader failed for row {}\", id, e);\n    }\n    throw e;\n}","preventionTips":["Validate JSON column contents (DB constraint or app-side parse) at write time","Pin the Hibernate version that matches your tested document shapes; re-test aggregates on upgrade","Keep a reproducer harness that can dump the failing document when parser errors appear"],"tags":["hibernate","json","parser","state-machine","data-corruption"],"backgroundTag":"malformed-json-parse","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}