prestodb/presto · error · IllegalArgumentException
values length is less than positionCount
Error message
values length is less than positionCount
What it means
ByteArrayBlock's constructor validates that the values array contains at least positionCount readable bytes after accounting for arrayOffset. The library throws IllegalArgumentException when values.length - arrayOffset < positionCount because the block would otherwise be unable to serve positionCount positions without reading out of bounds. It is a data-consistency guard, not a runtime condition.
Source
Thrown at presto-common/src/main/java/com/facebook/presto/common/block/ByteArrayBlock.java:75
public ByteArrayBlock(int positionCount, Optional<boolean[]> valueIsNull, byte[] values)
{
this(0, positionCount, valueIsNull.orElse(null), values);
}
ByteArrayBlock(int arrayOffset, int positionCount, boolean[] valueIsNull, byte[] 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
- Adjust positionCount (or arrayOffset) so that values.length - arrayOffset >= positionCount
- Trim the values array to exactly positionCount elements, e.g. Arrays.copyOfRange(values, arrayOffset, arrayOffset + positionCount)
- Check the caller that computes positionCount (e.g. a deserializer or page decoder) for off-by-one or wrong-buffer errors
- Verify you are constructing the block with the intended arrays — swapped or stale buffers from a previous call are a common cause
Example fix
// before new ByteArrayBlock(100, Optional.empty(), new byte[50], null); // throws // after new ByteArrayBlock(50, Optional.empty(), new byte[50], null);
Defensive patterns
Strategy: validation
Validate before calling
if (values.length - arrayOffset < positionCount) {
throw new IllegalArgumentException(
"values.length=" + values.length + " arrayOffset=" + arrayOffset +
" < positionCount=" + positionCount);
}
ByteArrayBlock block = new ByteArrayBlock(positionCount, valueIsNull, values);
Type guard
boolean canBuildByteArrayBlock(int positionCount, int arrayOffset, byte[] values) {
return positionCount >= 0 && arrayOffset >= 0 && values.length - arrayOffset >= positionCount;
}
Try / catch
try {
Block block = new ByteArrayBlock(positionCount, Optional.empty(), values, null);
} catch (IllegalArgumentException e) {
log.error("Invalid block construction: %s", e.getMessage());
throw new IllegalArgumentException("values array does not cover positionCount", e);
}
Prevention
- Always derive positionCount from the actual array size (or vice versa) at the construction site
- When slicing with arrayOffset, subtract it from the available length before setting positionCount
- Add asserts in deserialization code comparing buffer length to declared positionCount
When it happens
Trigger: Calling new ByteArrayBlock(positionCount, Optional.empty(), values, valueIsNull) (or the arrayOffset overload) with a values array shorter than positionCount minus arrayOffset; wrapping a sliced/offset buffer without shrinking positionCount accordingly; building a block from a partially-filled serialization buffer.
Common situations: Custom Block implementations or serialization code miscomputing positionCount after array slicing; code upgraded across Presto versions where the ByteArrayBlock constructor signature changed (valueIsNull made Optional and length checks enforced); tests constructing blocks by hand.
Related errors
- isNull length is less than positionCount
- values length is less than positionCount
- values length is less than positionCount
- dictionarySourceIds must be the same
- blocks is empty
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/b65a907aaa0cb604.
Report an issue: GitHub.