prestodb/presto · error · IllegalArgumentException
values length is less than positionCount
Error message
values length is less than positionCount
What it means
IntArrayBlock checks that the backing int[] values array has enough room: values.length - arrayOffset must be >= positionCount. If the array cannot supply that many positions from arrayOffset onward, the constructor throws IllegalArgumentException to prevent out-of-bounds reads later.
Source
Thrown at presto-common/src/main/java/com/facebook/presto/common/block/IntArrayBlock.java:68
public IntArrayBlock(int positionCount, Optional<boolean[]> valueIsNull, int[] values)
{
this(0, positionCount, valueIsNull.orElse(null), values);
}
IntArrayBlock(int arrayOffset, int positionCount, boolean[] valueIsNull, int[] values)
{
if (arrayOffset < 0) {
throw new IllegalArgumentException("arrayOffset is negative");
}
this.arrayOffset = arrayOffset;
if (positionCount < 0) {
throw new IllegalArgumentException("positionCount is negative");
}
this.positionCount = positionCount;
if (values.length - arrayOffset < positionCount) {
throw new IllegalArgumentException("values length is less than positionCount");
}
this.values = values;
if (valueIsNull != null && valueIsNull.length - arrayOffset < positionCount) {
throw new IllegalArgumentException("isNull length is less than positionCount");
}
this.valueIsNull = valueIsNull;
retainedSizeInBytes = INSTANCE_SIZE + sizeOf(valueIsNull) + sizeOf(values);
}
@Override
public long getSizeInBytes()
{
return SIZE_IN_BYTES_PER_POSITION * (long) positionCount;
}
@OverrideView on GitHub (pinned to 55bb57d202)
Solutions
- Ensure values.length >= arrayOffset + positionCount before constructing (grow the array or reduce positionCount).
- Recompute positionCount as the actual number of ints available (values.length - arrayOffset) when the array is the source of truth.
- Verify the array wasn't reallocated/truncated after the count was computed.
Example fix
// before IntArrayBlock block = new IntArrayBlock(offset, values.length + 1, nulls, values); // after IntArrayBlock block = new IntArrayBlock(offset, values.length - offset, nulls, values);
Defensive patterns
Strategy: validation
Validate before calling
if (values.length - arrayOffset < positionCount) {
throw new IllegalArgumentException("values array too small for offset+count");
}
IntArrayBlock block = new IntArrayBlock(arrayOffset, positionCount, valueIsNull, values); Type guard
boolean valuesFit(int[] values, int arrayOffset, int positionCount) {
return values != null && values.length - arrayOffset >= positionCount;
} Try / catch
try {
block = new IntArrayBlock(offset, count, nulls, values);
} catch (IllegalArgumentException e) {
block = new IntArrayBlock(offset, values.length - offset, nulls, values); // clamp count
} Prevention
- Recompute positionCount from the array whenever the array is authoritative
- Grow arrays before constructing blocks that reference more positions
- Check for arrays reallocated smaller by pooling/reuse code
When it happens
Trigger: Constructing the block with a values array shorter than arrayOffset + positionCount — e.g. shrinking a buffer without adjusting positionCount, or reusing a constructor call's stale count after compacting the array.
Common situations: Buffer reuse pools where the array was reallocated smaller; off-by-one in capacity math when appending; callers passing positionCount that includes entries trimmed from the array.
Related errors
- values length is less than positionCount
- Offset is not monotonically ascending. offsets[%s]=%s, offse
- A null map must have zero entries
- Number of fields in RowBlock must be positive
- position is not valid
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/ba5cf9fba585c4aa.
Report an issue: GitHub.