{"record":{"id":"ed67f44acfda8966","repo":"hibernate/hibernate-orm","slug":"foreachremaining","errorCode":null,"errorMessage":"forEachRemaining","messagePattern":"forEachRemaining","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"hibernate-core/src/main/java/org/hibernate/type/format/JsonDocumentReader.java","lineNumber":84,"sourceCode":" *    JsonDocumentItemType.ARRAY_START\n *    JsonDocumentItemType.VALUE          // \"a\"\n *    JsonDocumentItemType.ARRAY_END\n *    JsonDocumentItemType.VALUE_KEY       // \"key5\"\n *    JsonDocumentItemType.OBJECT_START\n *    JsonDocumentItemType.OBJECT_END\n *    JsonDocumentItemType.VALUE_KEY       // \"key6\"\n *    JsonDocumentItemType.NUMERIC_VALUE\n *    JsonDocumentItemType.VALUE_KEY       // \"key7\"\n *    JsonDocumentItemType.NULL_VALUE\n *    JsonDocumentItemType.OBJECT_END\n *    JsonDocumentItemType.OBJECT_END\n *  </pre>\n *\n * @author Emmanuel Jannetti\n */\npublic interface JsonDocumentReader extends Iterator<JsonDocumentItemType> {\n\tdefault void forEachRemaining() {\n\t\tthrow new UnsupportedOperationException(\"forEachRemaining\");\n\t}\n\n\t/**\n\t * Gets the key name once JsonDocumentItemType.VALUE_KEY has been received\n\t * @return the name\n\t */\n\tString getObjectKeyName();\n\t/**\n\t * Gets value as String\n\t * @return the value.\n\t */\n\tString getStringValue();\n\t/**\n\t * Gets value as BigDecimal\n\t * @return the value.\n\t */\n\tBigDecimal getBigDecimalValue();\n\t/**","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/format/JsonDocumentReader.java#L66-L102","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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()"],"exampleFix":"// before\nreader.forEachRemaining(); // always throws UnsupportedOperationException\n\n// after\nwhile (reader.hasNext()) {\n    JsonDocumentItemType item = reader.next();\n    // consume typed getters here, before the next next()\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["hibernate","json","iterator","api-misuse","document-reader"],"backgroundTag":"unsupported-iterator-operation","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}