pinpoint-apm/pinpoint · error · ArrayIndexOutOfBoundsException

End index must not be greater than the array length

Error message

End index must not be greater than the array length

What it means

ObjectArrayIterator validates its end index in the constructor: if end > array.length it throws ArrayIndexOutOfBoundsException, since iteration would read past the array. The javadoc also documents IllegalArgumentException when end is before start, but this specific message is the out-of-bounds case.

Source

Thrown at agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/queue/ObjectArrayIterator.java:69

     */
    public ObjectArrayIterator(final E array[]) {
        this(array, array.length);
    }

    /**
     * Construct an ObjectArrayIterator that will iterate over a range of values
     * in the specified array.
     *
     * @param array  the array to iterate over
     * @param end  the index (exclusive) to finish iterating at
     * @throws IndexOutOfBoundsException if the start or end index is out of bounds
     * @throws IllegalArgumentException if end index is before the start
     * @throws NullPointerException if <code>array</code> is <code>null</code>
     */
    public ObjectArrayIterator(final E array[], final int end) {
        super();
        if (end > array.length) {
            throw new ArrayIndexOutOfBoundsException("End index must not be greater than the array length");
        }

        this.array = array;
        this.endIndex = end;
        this.index = 0;
    }

    // Iterator interface
    //-------------------------------------------------------------------------

    /**
     * Returns true if there are more elements to return from the array.
     *
     * @return true if there is a next element to return
     */
    @Override
    public boolean hasNext() {
        return this.index < this.endIndex;

View on GitHub (pinned to 744c3d3075)

Solutions

  1. Pass end = array.length to iterate the whole array
  2. Clamp: end = Math.min(end, array.length)
  3. Verify the end offset belongs to the same array passed in

Example fix

// before
new ObjectArrayIterator<>(array, end);
// after
new ObjectArrayIterator<>(array, Math.min(end, array.length));
Defensive patterns

Strategy: validation

Validate before calling

int safeEnd = Math.min(end, array.length);
Iterator<E> it = new ObjectArrayIterator<>(array, safeEnd);

Try / catch

try { it = new ObjectArrayIterator<>(array, end); } catch (ArrayIndexOutOfBoundsException e) { it = new ObjectArrayIterator<>(array); }

Prevention

When it happens

Trigger: new ObjectArrayIterator<>(array, end) with end > array.length — e.g. passing a computed limit, a size from another array, or length+1 by mistake.

Common situations: Wrapping a drained buffer with a stale end offset; misusing the constructor believing end is exclusive-beyond-length rather than capped at length.

Related errors


AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07). Data as JSON: /api/errors/6c1769cbd2e23faa. Report an issue: GitHub.