hibernate/hibernate-orm · warning · UnsupportedOperationException

forEachRemaining

Error message

forEachRemaining

What it means

JsonDocumentReader is a pull-style event iterator; each next() both advances the parse and refreshes the typed accessors (getStringValue, getBigDecimalValue, ...). The interface ships a no-argument default forEachRemaining() that unconditionally throws UnsupportedOperationException - it is deliberately NOT an override of Iterator.forEachRemaining(Consumer); it exists as a guard so integrators do not bulk-drain the reader and lose the per-item accessor protocol.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/format/JsonDocumentReader.java:84

 *    JsonDocumentItemType.ARRAY_START
 *    JsonDocumentItemType.VALUE          // "a"
 *    JsonDocumentItemType.ARRAY_END
 *    JsonDocumentItemType.VALUE_KEY       // "key5"
 *    JsonDocumentItemType.OBJECT_START
 *    JsonDocumentItemType.OBJECT_END
 *    JsonDocumentItemType.VALUE_KEY       // "key6"
 *    JsonDocumentItemType.NUMERIC_VALUE
 *    JsonDocumentItemType.VALUE_KEY       // "key7"
 *    JsonDocumentItemType.NULL_VALUE
 *    JsonDocumentItemType.OBJECT_END
 *    JsonDocumentItemType.OBJECT_END
 *  </pre>
 *
 * @author Emmanuel Jannetti
 */
public interface JsonDocumentReader extends Iterator<JsonDocumentItemType> {
	default void forEachRemaining() {
		throw new UnsupportedOperationException("forEachRemaining");
	}

	/**
	 * Gets the key name once JsonDocumentItemType.VALUE_KEY has been received
	 * @return the name
	 */
	String getObjectKeyName();
	/**
	 * Gets value as String
	 * @return the value.
	 */
	String getStringValue();
	/**
	 * Gets value as BigDecimal
	 * @return the value.
	 */
	BigDecimal getBigDecimalValue();
	/**

View on GitHub (pinned to fad1729dce)

Solutions

  1. Iterate manually: while (reader.hasNext()) { JsonDocumentItemType item = reader.next(); ... }
  2. Do not bulk-consume the reader - typed getters are only valid immediately after the matching next()
  3. If you need a stream, wrap the reader yourself, capturing values right after each next()

Example fix

// before
reader.forEachRemaining(); // always throws UnsupportedOperationException

// after
while (reader.hasNext()) {
    JsonDocumentItemType item = reader.next();
    // consume typed getters here, before the next next()
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Calling reader.forEachRemaining() with no arguments directly on a JsonDocumentReader - it always throws; typically integrator or test code that assumed a Stream-like convenience method exists on the reader.

Common situations: Custom code driving JsonDocumentReader for aggregate mappings or tests; IDE auto-complete picking the no-arg method; copying Iterator idioms onto this reader without reading its protocol.

Related errors


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