prestodb/presto · error · IllegalArgumentException

isNull length is less than positionCount

Error message

isNull length is less than positionCount

What it means

IntArrayBlock also validates the optional null bitmap: when valueIsNull is non-null, valueIsNull.length - arrayOffset must be >= positionCount so every position has a corresponding null flag. A too-short boolean[] throws IllegalArgumentException.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/block/IntArrayBlock.java:73

    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;
    }

    @Override
    public OptionalInt fixedSizeInBytesPerPosition()
    {
        return OptionalInt.of(SIZE_IN_BYTES_PER_POSITION);
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Ensure valueIsNull is either null or has length >= arrayOffset + positionCount; rebuild the nulls array to match.
  2. Apply the same arrayOffset/slicing to both arrays.
  3. If nulls are absent, pass null explicitly instead of a short placeholder array.

Example fix

// before
boolean[] nulls = new boolean[count]; // missing offset room
new IntArrayBlock(offset, count, nulls, values);
// after
boolean[] nulls = new boolean[offset + count];
new IntArrayBlock(offset, count, nulls, values);
Defensive patterns

Strategy: validation

Validate before calling

if (valueIsNull != null && valueIsNull.length - arrayOffset < positionCount) {
    valueIsNull = Arrays.copyOf(valueIsNull, arrayOffset + positionCount); // pad to fit
}

Type guard

boolean nullsFit(boolean[] valueIsNull, int arrayOffset, int positionCount) {
    return valueIsNull == null || valueIsNull.length - arrayOffset >= positionCount;
}

Try / catch

try {
    block = new IntArrayBlock(offset, count, nulls, values);
} catch (IllegalArgumentException e) {
    nulls = nulls == null ? null : Arrays.copyOf(nulls, offset + count);
    block = new IntArrayBlock(offset, count, nulls, values);
}

Prevention

When it happens

Trigger: Passing a valueIsNull array built for a different (larger) positionCount, or built without accounting for arrayOffset, while values happens to be long enough — so the mismatch surfaces on the null array check.

Common situations: Null bitmap and values arrays produced by separate code paths with different offsets; truncating only one of the two arrays; adapting blocks from another engine where the null mask excludes an offset region.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/da52c3b34b3fa1fa. Report an issue: GitHub.