prestodb/presto · error · IllegalArgumentException
arrayOffset is negative
Error message
arrayOffset is negative
What it means
ShortArrayBlock stores a shared backing array with an offset window into it; the package-private constructor validates that arrayOffset and positionCount are non-negative so that position indexing (arrayOffset + position) is always in bounds. A negative arrayOffset indicates corrupted slice parameters and fails fast with IllegalArgumentException.
Source
Thrown at presto-common/src/main/java/com/facebook/presto/common/block/ShortArrayBlock.java:57
public static final int SIZE_IN_BYTES_PER_POSITION = Short.BYTES + Byte.BYTES;
private final int arrayOffset;
private final int positionCount;
@Nullable
private final boolean[] valueIsNull;
private final short[] values;
private final long retainedSizeInBytes;
public ShortArrayBlock(int positionCount, Optional<boolean[]> valueIsNull, short[] values)
{
this(0, positionCount, valueIsNull.orElse(null), values);
}
ShortArrayBlock(int arrayOffset, int positionCount, boolean[] valueIsNull, short[] 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);View on GitHub (pinned to 55bb57d202)
Solutions
- Check offset arguments are >= 0 before invoking the constructor (or its factory methods)
- Fix the offset computation (e.g. a start index that went negative) in the calling block code
- Upgrade/regress to a Presto version without the block-slicing bug if this arises from internal compaction code
Example fix
// before return new ShortArrayBlock(offset, count, valueIsNull, values); // offset computed, may be negative // after checkArgument(offset >= 0, "arrayOffset is negative: %s", offset); return new ShortArrayBlock(offset, count, valueIsNull, values);
Defensive patterns
Strategy: validation
Validate before calling
// before constructing ShortArrayBlock (or calling factories that slice)
if (arrayOffset < 0) {
throw new IllegalArgumentException("arrayOffset computed as " + arrayOffset + " is negative");
}
Try / catch
try {
return new ShortArrayBlock(arrayOffset, positionCount, valueIsNull, values);
} catch (IllegalArgumentException e) {
if (e.getMessage().equals("arrayOffset is negative")) {
throw new IllegalStateException("negative slice offset " + arrayOffset + "; check slicing arithmetic", e);
}
throw e;
} Prevention
- Validate start/offset arithmetic before slicing blocks
- Clamp offsets with Math.max(0, ...) where underflow is possible
- Add assertions in block-region-copy helpers that offsets are non-negative
When it happens
Trigger: Constructing ShortArrayBlock with a negative arrayOffset — typically only reachable from internal factory methods (wrapSlice, getRegion copying, block compaction) that compute offsets via subtraction or slicing of a parent block.
Common situations: Custom block code copying regions with wrong start offsets; regression in block compaction/retention logic after block layout changes between Presto versions.
Related errors
- Expected value to contain a single position but has %s posit
- array1 and array2 cannot be null and should have same length
- arrayOffset is negative
- positionCount is negative
- positionCount is negative
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/35d3864f2fca3ba6.
Report an issue: GitHub.