{"record":{"id":"927a5717a02d1a7e","repo":"hibernate/hibernate-orm","slug":"no-available-value","errorCode":null,"errorMessage":"No available value","messagePattern":"No available value","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java","lineNumber":390,"sourceCode":"\t}\n\n\t/**\n\t * Ensures that the current state is on value.\n\t * @throws IllegalStateException if not on \"value\" state\n\t */\n\tprivate void ensureValueState() throws IllegalStateException {\n\t\tif ( (this.processingStates.getCurrent() != JsonProcessingState.OBJECT ) &&\n\t\t\tthis.processingStates.getCurrent() != JsonProcessingState.ARRAY)  {\n\t\t\tthrow new IllegalStateException( \"unexpected processing state: \" + this.processingStates.getCurrent() );\n\t\t}\n\t}\n\t/**\n\t * Ensures that we have a value ready to be exposed. i.e we just consume one.\n\t * @throws IllegalStateException if no value available\n\t */\n\tprivate void ensureAvailableValue() throws IllegalStateException {\n\t\tif (this.jsonValueEnd == 0 ) {\n\t\t\tthrow new IllegalStateException( \"No available value\");\n\t\t}\n\t}\n\n\t@Override\n\tpublic String getObjectKeyName() {\n\t\tif ( this.processingStates.getCurrent() != JsonProcessingState.OBJECT_KEY_NAME ) {\n\t\t\tthrow new IllegalStateException( \"unexpected processing state: \" + this.processingStates.getCurrent() );\n\t\t}\n\t\tensureAvailableValue();\n\t\treturn this.jsonString.substring( this.jsonValueStart, this.jsonValueEnd);\n\t}\n\n\t@Override\n\tpublic String getStringValue() {\n\t\tensureValueState();\n\t\tensureAvailableValue();\n\t\tif ( currentValueHasEscape()) {\n\t\t\treturn unescape(this.jsonString, this.jsonValueStart , this.jsonValueEnd);","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java#L372-L408","documentation":"Typed getters also call ensureAvailableValue(), which requires that a value token window was actually captured (jsonValueEnd != 0). The window starts at zero on a fresh reader and is reset by structural items (OBJECT_START/OBJECT_END/ARRAY_START/ARRAY_END call resetValueWindow()), so this exception means 'no value has been consumed yet' — a getter was called before next() returned a value item.","triggerScenarios":"Calling getStringValue()/getIntegerValue()/... before the first next(), immediately after constructing the reader, or right after next() returned OBJECT_START, OBJECT_END, ARRAY_START or ARRAY_END (all of which clear the value window).","commonSituations":"Traversal code that reads the value before advancing the iterator; event handlers that call a getter for structural events; code ported from a push-style parser where values arrive in callbacks.","solutions":["Only call value getters after next() returned VALUE, NUMERIC_VALUE, BOOLEAN_VALUE or NULL_VALUE","Handle structural items (OBJECT_START, ARRAY_START, ...) separately and never read a value for them","If getObjectKeyName() passes its state check but throws 'No available value', the key token was never consumed — call next() first"],"exampleFix":"// before\nStringJsonDocumentReader reader = new StringJsonDocumentReader(json);\nString v = reader.getStringValue(); // IllegalStateException: no value consumed yet\n// after\nreader.next(); // advances to a value item (e.g. VALUE)\nString v2 = reader.getStringValue();","handlingStrategy":"validation","validationCode":"static boolean valueConsumed(JsonDocumentItemType lastItem) {\n    return lastItem != null\n            && lastItem != JsonDocumentItemType.OBJECT_START\n            && lastItem != JsonDocumentItemType.OBJECT_END\n            && lastItem != JsonDocumentItemType.ARRAY_START\n            && lastItem != JsonDocumentItemType.ARRAY_END;\n}\n\n// only call getStringValue()/getIntegerValue()/... when valueConsumed(lastItem) is true","typeGuard":null,"tryCatchPattern":"try {\n    value = reader.getStringValue();\n} catch (IllegalStateException e) {\n    if (\"No available value\".equals(e.getMessage())) {\n        // next() has not returned a value item yet - advance the reader first\n        reader.next();\n        return reader.getStringValue();\n    }\n    throw e;\n}","preventionTips":["Never call a getter before the first next()","Structural items (OBJECT_START, ARRAY_END, ...) carry no value - do not read one for them","Unit-test custom readers/mappers with minimal documents: {}, {\"k\":1}, [1], \"s\""],"tags":["hibernate","json","parser","api-misuse"],"backgroundTag":"invalid-parser-state","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}