prestodb/presto · error · IllegalArgumentException

positionCount is negative

Error message

positionCount is negative

What it means

Defensive argument check inside ArrayBlock's validation helper: the requested positionCount for the block is negative, which can never describe a valid block layout. It fires only from internal construction paths (createArrayBlockInternal / fromElementBlock), meaning a caller passed a malformed size rather than user data being bad.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/block/ArrayBlock.java:82

    }

    /**
     * Create an array block directly without per element validations.
     */
    static ArrayBlock createArrayBlockInternal(int arrayOffset, int positionCount, @Nullable boolean[] valueIsNull, int[] offsets, Block values)
    {
        validateConstructorArguments(arrayOffset, positionCount, valueIsNull, offsets, values);
        return new ArrayBlock(arrayOffset, positionCount, valueIsNull, offsets, values);
    }

    private static void validateConstructorArguments(int arrayOffset, int positionCount, @Nullable boolean[] valueIsNull, int[] offsets, Block values)
    {
        if (arrayOffset < 0) {
            throw new IllegalArgumentException("arrayOffset is negative");
        }

        if (positionCount < 0) {
            throw new IllegalArgumentException("positionCount is negative");
        }

        if (valueIsNull != null && valueIsNull.length - arrayOffset < positionCount) {
            throw new IllegalArgumentException("isNull length is less than positionCount");
        }

        requireNonNull(offsets, "offsets is null");
        if (offsets.length - arrayOffset < positionCount + 1) {
            throw new IllegalArgumentException("offsets length is less than positionCount");
        }

        requireNonNull(values, "values is null");
    }

    /**
     * Use createArrayBlockInternal or fromElementBlock instead of this method.  The caller of this method is assumed to have
     * validated the arguments with validateConstructorArguments.
     */

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Fix the computation of positionCount at the construction site
  2. Clamp or validate counts derived from external sizes before building the block
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-common/src/main/java/com/facebook/presto/common/block/ArrayBlock.java:82 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/7439c5ca52f0a64f. Report an issue: GitHub.