prestodb/presto · error · IllegalStateException
cannot do sequential write after getFieldBlockBuilder is cal
Error message
cannot do sequential write after getFieldBlockBuilder is called
What it means
checkFieldIndexToWrite enforces the reverse rule of error 410: after getFieldBlockBuilder hands out a field block builder, sequential writes are forbidden. Any sequential write method (writeByte, writeShort, writeInt, writeLong, writeBytes, appendStructure) throws IllegalStateException because mixing modes would corrupt field offsets.
Source
Thrown at presto-common/src/main/java/com/facebook/presto/common/block/SingleRowBlockWriter.java:263
{
throw new UnsupportedOperationException();
}
@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
- Write every field through the obtained field block builders once getFieldBlockBuilder has been used.
- Choose exactly one write mode per row writer before serializing.
- Reset by completing the current row and creating a new SingleRowBlockWriter.
Example fix
// before BlockBuilder f = writer.getFieldBlockBuilder(0); writer.writeLong(1, value); // throws // after BlockBuilder f = writer.getFieldBlockBuilder(0); BlockBuilder f1 = writer.getFieldBlockBuilder(1); f1.writeLong(value);
Defensive patterns
Strategy: validation
Validate before calling
checkState(!fieldBuildersObtained, "use field builders for all writes once obtained");
Try / catch
try {
writer.writeLong(idx, value);
} catch (IllegalStateException e) {
// sequential write after getFieldBlockBuilder: route through field builder
} Prevention
- Route all field writes through field block builders once getFieldBlockBuilder is used
- Encode the chosen write mode in the serializer's type dispatch so it cannot mix
- Add unit tests covering every field type path in the row encoder
When it happens
Trigger: Calling writeByte/writeShort/writeInt/writeLong/writeBytes/appendStructure on a SingleRowBlockWriter after getFieldBlockBuilder() has been called on that writer instance.
Common situations: Type serializers that take the field-builder path for one field but fall back to sequential writes for another field within the same row; generic serialization code that checks types at runtime and mixes both APIs.
Related errors
- field block builder can only be obtained before any sequenti
- 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 has been returned
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/cc8cb65c5ad3d732.
Report an issue: GitHub.