{"record":{"id":"6c1769cbd2e23faa","repo":"pinpoint-apm/pinpoint","slug":"end-index-must-not-be-greater-than-the-array-lengt-6c1769","errorCode":null,"errorMessage":"End index must not be greater than the array length","messagePattern":"End index must not be greater than the array length","errorType":"exception","errorClass":"ArrayIndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/queue/ObjectArrayIterator.java","lineNumber":69,"sourceCode":"     */\n    public ObjectArrayIterator(final E array[]) {\n        this(array, array.length);\n    }\n\n    /**\n     * Construct an ObjectArrayIterator that will iterate over a range of values\n     * in the specified array.\n     *\n     * @param array  the array to iterate over\n     * @param end  the index (exclusive) to finish iterating at\n     * @throws IndexOutOfBoundsException if the start or end index is out of bounds\n     * @throws IllegalArgumentException if end index is before the start\n     * @throws NullPointerException if <code>array</code> is <code>null</code>\n     */\n    public ObjectArrayIterator(final E array[], final int end) {\n        super();\n        if (end > array.length) {\n            throw new ArrayIndexOutOfBoundsException(\"End index must not be greater than the array length\");\n        }\n\n        this.array = array;\n        this.endIndex = end;\n        this.index = 0;\n    }\n\n    // Iterator interface\n    //-------------------------------------------------------------------------\n\n    /**\n     * Returns true if there are more elements to return from the array.\n     *\n     * @return true if there is a next element to return\n     */\n    @Override\n    public boolean hasNext() {\n        return this.index < this.endIndex;","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/queue/ObjectArrayIterator.java#L51-L87","documentation":"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.","triggerScenarios":"new ObjectArrayIterator<>(array, end) with end > array.length — e.g. passing a computed limit, a size from another array, or length+1 by mistake.","commonSituations":"Wrapping a drained buffer with a stale end offset; misusing the constructor believing end is exclusive-beyond-length rather than capped at length.","solutions":["Pass end = array.length to iterate the whole array","Clamp: end = Math.min(end, array.length)","Verify the end offset belongs to the same array passed in"],"exampleFix":"// before\nnew ObjectArrayIterator<>(array, end);\n// after\nnew ObjectArrayIterator<>(array, Math.min(end, array.length));","handlingStrategy":"validation","validationCode":"int safeEnd = Math.min(end, array.length);\nIterator<E> it = new ObjectArrayIterator<>(array, safeEnd);","typeGuard":null,"tryCatchPattern":"try { it = new ObjectArrayIterator<>(array, end); } catch (ArrayIndexOutOfBoundsException e) { it = new ObjectArrayIterator<>(array); }","preventionTips":["Use array.length for full-array iteration","Clamp any externally supplied end value","Confirm end/start belong to the same array"],"tags":["java","iterator","index-out-of-bounds"],"backgroundTag":"index-out-of-bounds","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}