hibernate/hibernate-orm · error · IllegalStateException
No available value
Error message
No available value
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java:390
}
/**
* Ensures that the current state is on value.
* @throws IllegalStateException if not on "value" state
*/
private void ensureValueState() throws IllegalStateException {
if ( (this.processingStates.getCurrent() != JsonProcessingState.OBJECT ) &&
this.processingStates.getCurrent() != JsonProcessingState.ARRAY) {
throw new IllegalStateException( "unexpected processing state: " + this.processingStates.getCurrent() );
}
}
/**
* Ensures that we have a value ready to be exposed. i.e we just consume one.
* @throws IllegalStateException if no value available
*/
private void ensureAvailableValue() throws IllegalStateException {
if (this.jsonValueEnd == 0 ) {
throw new IllegalStateException( "No available value");
}
}
@Override
public String getObjectKeyName() {
if ( this.processingStates.getCurrent() != JsonProcessingState.OBJECT_KEY_NAME ) {
throw new IllegalStateException( "unexpected processing state: " + this.processingStates.getCurrent() );
}
ensureAvailableValue();
return this.jsonString.substring( this.jsonValueStart, this.jsonValueEnd);
}
@Override
public String getStringValue() {
ensureValueState();
ensureAvailableValue();
if ( currentValueHasEscape()) {
return unescape(this.jsonString, this.jsonValueStart , this.jsonValueEnd);View on GitHub (pinned to fad1729dce)
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
Example fix
// before StringJsonDocumentReader reader = new StringJsonDocumentReader(json); String v = reader.getStringValue(); // IllegalStateException: no value consumed yet // after reader.next(); // advances to a value item (e.g. VALUE) String v2 = reader.getStringValue();
Defensive patterns
Strategy: validation
Validate before calling
static boolean valueConsumed(JsonDocumentItemType lastItem) {
return lastItem != null
&& lastItem != JsonDocumentItemType.OBJECT_START
&& lastItem != JsonDocumentItemType.OBJECT_END
&& lastItem != JsonDocumentItemType.ARRAY_START
&& lastItem != JsonDocumentItemType.ARRAY_END;
}
// only call getStringValue()/getIntegerValue()/... when valueConsumed(lastItem) is true Try / catch
try {
value = reader.getStringValue();
} catch (IllegalStateException e) {
if ("No available value".equals(e.getMessage())) {
// next() has not returned a value item yet - advance the reader first
reader.next();
return reader.getStringValue();
}
throw e;
} Prevention
- 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"
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- unexpected processing state: {}
- forEachRemaining
- Unknown OSON event: {}
- Unexpected JsonProcessingState {}
- unexpected quote read in current processing state {}
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/927a5717a02d1a7e.
Report an issue: GitHub.