prestodb/presto · error · IndexOutOfBoundsException

Invalid offset %s and length %s in array with %s elements

Error message

Invalid offset %s and length %s in array with %s elements

What it means

checkArrayRange guard: offset or length is negative or offset+length exceeds the int[] capacity, so the requested slice of the array (offsets/isNull backing arrays) is out of bounds — an internal block-util invariant violation.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/block/BlockUtil.java:46

import static java.util.Objects.requireNonNull;

public final class BlockUtil
{
    private static final double BLOCK_RESET_SKEW = 1.25;

    private static final int DEFAULT_CAPACITY = 64;
    // See java.util.ArrayList for an explanation
    static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;

    private BlockUtil()
    {
    }

    static void checkArrayRange(int[] array, int offset, int length)
    {
        requireNonNull(array, "array is null");
        if (offset < 0 || length < 0 || offset + length > array.length) {
            throw new IndexOutOfBoundsException(format("Invalid offset %s and length %s in array with %s elements", offset, length, array.length));
        }
    }

    static void checkArrayRange(boolean[] array, int offset, int length)
    {
        requireNonNull(array, "array is null");
        if (offset < 0 || length < 0 || offset + length > array.length) {
            throw new IndexOutOfBoundsException(format("Invalid offset %s and length %s in array with %s elements", offset, length, array.length));
        }
    }

    static void checkValidRegion(int positionCount, int positionOffset, int length)
    {
        if (positionOffset < 0 || length < 0 || positionOffset + length > positionCount) {
            throw new IndexOutOfBoundsException(format("Invalid position %s and length %s in block with %s positions", positionOffset, length, positionCount));
        }
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Validate offset+length against array length before calling
  2. Fix the caller's offset arithmetic when computing selected ranges
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-common/src/main/java/com/facebook/presto/common/block/BlockUtil.java:46 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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