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
- Iterate manually: while (reader.hasNext()) { JsonDocumentItemType item = reader.next(); ... }
- Do not bulk-consume the reader - typed getters are only valid immediately after the matching next()
- 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
- Never call forEachRemaining() in any form on JsonDocumentReader
- Consume typed getters immediately after the matching next()
- Encapsulate reader loops in one helper so the protocol is honored in a single place
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
- Unsupported type of document reader
- No more item in JSON document
- no object key available
- json cannot be null
- no more elements
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/ed67f44acfda8966.
Report an issue: GitHub.