hibernate/hibernate-orm · error · IllegalStateException

Unexpected JsonProcessingState {}

Error message

Unexpected JsonProcessingState {}

What it means

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java:131

				this.processingStates.pop();
				assert this.processingStates.getCurrent() == JsonProcessingState.OBJECT;
				break;
			case QUOTE:
				if (currentState == JsonProcessingState.STARTING_ARRAY) {
					this.processingStates.push( JsonProcessingState.ARRAY );
				}
				if (currentState == JsonProcessingState.STARTING_OBJECT) {
					this.processingStates.push( JsonProcessingState.OBJECT );
					this.processingStates.push( JsonProcessingState.OBJECT_KEY_NAME );
				}
				break;
			case OTHER:
				if ( currentState == JsonProcessingState.STARTING_ARRAY) {
					this.processingStates.push( JsonProcessingState.ARRAY );
				}
				break;
			default:
				throw new IllegalStateException( "Unexpected JsonProcessingState " + marker );
		}
	}

	/**
	 * Returns the next item.
	 * @return the item
	 * @throws NoSuchElementException no more item available
	 * @throws IllegalStateException not a well-formed JSON string.
	 */
	@Override
	public JsonDocumentItemType next() {

		if ( !hasNext()) throw new NoSuchElementException("no more elements");

		while (hasNext()) {
			skipWhiteSpace();
			StringJsonDocumentMarker marker = StringJsonDocumentMarker.markerOf( this.jsonString.charAt( this.position++ ) );
			moveStateMachine( marker );

View on GitHub (pinned to fad1729dce)

Solutions

  1. 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
  2. Upgrade (or, for a regression, roll back) Hibernate ORM - this parser is actively fixed
  3. Capture the exact failing payload and report a Hibernate issue with the mapping and document
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate documents from untrusted sources before they reach Hibernate's reader
com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
try { om.readTree(json); } catch (Exception e) { reject("not well-formed JSON", e); }

Try / catch

try {
    MyAgg agg = session.find(MyEntity.class, id).getAgg();
} catch (IllegalStateException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Unexpected JsonProcessingState")) {
        // parser invariant broken: capture payload, report upstream
        LOG.error("Hibernate string JSON reader failed for row {}", id, e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/3a1d731d83e7214d. Report an issue: GitHub.