prestodb/presto · error · IllegalStateException
Array reached maximum size
Error message
Array reached maximum size
What it means
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.
Source
Thrown at presto-common/src/main/java/com/facebook/presto/common/block/IntArrayList.java:51
throw new IllegalArgumentException(format("Initial capacity '%s' is negative", initialCapacity));
}
array = new int[initialCapacity];
}
IntArrayList()
{
this(DEFAULT_INITIAL_CAPACITY);
}
int[] elements()
{
return array;
}
private void grow(int newCapacity)
{
if (array.length == MAX_ARRAY_SIZE) {
throw new IllegalStateException("Array reached maximum size");
}
if (newCapacity > array.length) {
int newLength = (int) Math.min(Math.max(2L * (long) array.length, (long) newCapacity), MAX_ARRAY_SIZE);
array = Arrays.copyOf(array, newLength);
}
}
void add(int element)
{
grow(size + 1);
array[size++] = element;
}
int size()
{
return size;
}View on GitHub (pinned to 55bb57d202)
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
Defensive patterns
Strategy: validation
Validate before calling
if (list.size() >= IntArrayList.MAX_ARRAY_SIZE) {
throw new IllegalStateException("cannot append: array at maximum size");
}
list.add(value); Try / catch
try {
list.add(value);
} catch (IllegalStateException e) {
// split or spill accumulated data
} Prevention
- Bound the number of elements appended per block
- Partition large datasets before accumulating
- Watch for loops without termination conditions
When it happens
Trigger: Calling add() repeatedly on an IntArrayList whose array.length == MAX_ARRAY_SIZE, forcing another grow.
Common situations: 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.
Related errors
- Response does not contain a JSON value
- path is empty
- Invalid field position selection after nulls removed: " + se
- Map key is null at position: " + position
- Current entry must be closed before a null can be written
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/1957862f6e57bfde.
Report an issue: GitHub.