{"record":{"id":"1957862f6e57bfde","repo":"prestodb/presto","slug":"array-reached-maximum-size","errorCode":null,"errorMessage":"Array reached maximum size","messagePattern":"Array reached maximum size","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/IntArrayList.java","lineNumber":51,"sourceCode":"            throw new IllegalArgumentException(format(\"Initial capacity '%s' is negative\", initialCapacity));\n        }\n        array = new int[initialCapacity];\n    }\n\n    IntArrayList()\n    {\n        this(DEFAULT_INITIAL_CAPACITY);\n    }\n\n    int[] elements()\n    {\n        return array;\n    }\n\n    private void grow(int newCapacity)\n    {\n        if (array.length == MAX_ARRAY_SIZE) {\n            throw new IllegalStateException(\"Array reached maximum size\");\n        }\n\n        if (newCapacity > array.length) {\n            int newLength = (int) Math.min(Math.max(2L * (long) array.length, (long) newCapacity), MAX_ARRAY_SIZE);\n            array = Arrays.copyOf(array, newLength);\n        }\n    }\n\n    void add(int element)\n    {\n        grow(size + 1);\n        array[size++] = element;\n    }\n\n    int size()\n    {\n        return size;\n    }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/IntArrayList.java#L33-L69","documentation":"grow() throws IllegalStateException when the backing array has already reached MAX_ARRAY_SIZE and cannot be expanded further. IntArrayList intentionally caps its size below Integer.MAX_VALUE to avoid overflow bugs (e.g. from Arrays.copyOf). Thrown by add() once ~2^31-2 elements have accumulated.","triggerScenarios":"Calling add() repeatedly on an IntArrayList whose array.length == MAX_ARRAY_SIZE, forcing another grow.","commonSituations":"Aggregating extremely large column data or an unbounded loop appending positions without a size limit; usually indicates runaway data volume or a missing termination condition.","solutions":["Reduce the amount of data appended (split work into blocks/partitions)","Check for a runaway or non-terminating loop calling add()","Use a different structure (e.g. Block builders streamed to disk) for data beyond MAX_ARRAY_SIZE"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (list.size() >= IntArrayList.MAX_ARRAY_SIZE) {\n    throw new IllegalStateException(\"cannot append: array at maximum size\");\n}\nlist.add(value);","typeGuard":null,"tryCatchPattern":"try {\n    list.add(value);\n} catch (IllegalStateException e) {\n    // split or spill accumulated data\n}","preventionTips":["Bound the number of elements appended per block","Partition large datasets before accumulating","Watch for loops without termination conditions"],"tags":["illegal-state","collections","capacity-exceeded"],"backgroundTag":"collection-capacity-exceeded","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}