prestodb/presto · error · IllegalStateException
currentFieldIndexToWrite is not valid
Error message
currentFieldIndexToWrite is not valid
What it means
checkFieldIndexToWrite also validates that the sequential write cursor (currentFieldIndexToWrite) has not advanced past the number of field block builders in the row, i.e. the row has more sequential entries written than it has fields. This is an IllegalArgumentException-free IllegalStateException thrown when sequential writes overflow the row's field count.
Source
Thrown at presto-common/src/main/java/com/facebook/presto/common/block/SingleRowBlockWriter.java:266
@Override
public String toString()
{
if (!fieldBlockBuilderReturned) {
return format("SingleRowBlockWriter(%d){numFields=%d, fieldBlockBuilderReturned=false, positionCount=%d}", hashCode(), fieldBlockBuilders.length, getPositionCount());
}
else {
return format("SingleRowBlockWriter(%d){numFields=%d, fieldBlockBuilderReturned=true}", hashCode(), fieldBlockBuilders.length);
}
}
private void checkFieldIndexToWrite()
{
if (fieldBlockBuilderReturned) {
throw new IllegalStateException("cannot do sequential write after getFieldBlockBuilder is called");
}
if (currentFieldIndexToWrite >= fieldBlockBuilders.length) {
throw new IllegalStateException("currentFieldIndexToWrite is not valid");
}
}
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Verify the number of sequential writes matches the field count of the row type.
- Regenerate or update the encoder after any schema change to the row type.
- Add an assertion in the caller comparing planned field count with the writer's fieldBlockBuilders length before writing.
Example fix
// before
for (Object v : values) { writer.appendStructure(...); } // values larger than row arity
// after
checkState(values.size() == fieldCount, "row arity mismatch");
for (Object v : values) { writer.appendStructure(...); } Defensive patterns
Strategy: validation
Validate before calling
checkState(plannedFieldCount == expectedRowArity, "sequential writes exceed row field count");
Try / catch
try {
writer.appendStructure(value);
} catch (IllegalStateException e) {
// too many writes: schema/encoder mismatch, fail fast with schema info
} Prevention
- Derive write count from RowType.getParameters() rather than hardcoding
- Re-run encoder tests after every schema change
- Assert values.size() == row arity before writing
When it happens
Trigger: Performing more sequential writes (writeByte/writeShort/writeInt/writeLong/writeBytes/appendStructure) than the row has fields; e.g. appending an extra entry to a row whose type declares fewer fields.
Common situations: Serializer/schema mismatch: the RowType changed (column added/removed) but the encoder still writes the old number of values; miscounted fields in dynamic row construction.
Related errors
- Current entry must be closed before a null can be written
- Current entry must be closed before a null can be written
- Current entry must be closed before the block can be built
- field block builder can only be obtained before any sequenti
- field block builder has been returned
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/c0b2ae4540ca616e.
Report an issue: GitHub.