apache/druid · error · IAE
Size[%d] > expansion.length[%d] or < 0
Error message
Size[%d] > expansion.length[%d] or < 0
What it means
ArrayBasedIndexedInts.setSize(int) validates that the requested active size is non-negative and does not exceed the capacity of the internal expansion array, throwing IAE otherwise. It is used to reuse the object over a fixed backing array.
Source
Thrown at processing/src/main/java/org/apache/druid/segment/data/ArrayBasedIndexedInts.java:57
}
public ArrayBasedIndexedInts(int[] expansion)
{
this.expansion = expansion;
this.size = expansion.length;
}
public void ensureSize(int size)
{
if (expansion.length < size) {
expansion = new int[size];
}
}
public void setSize(int size)
{
if (size < 0 || size > expansion.length) {
throw new IAE("Size[%d] > expansion.length[%d] or < 0", size, expansion.length);
}
this.size = size;
}
/**
* Sets the values from the given array. The given values array is not reused and not prone to be mutated later.
* Instead, the values from this array are copied into an array which is internal to ArrayBasedIndexedInts.
*/
public void setValues(int[] values, int size)
{
if (size < 0 || size > values.length) {
throw new IAE("Size[%d] should be between 0 and %d", size, values.length);
}
ensureSize(size);
System.arraycopy(values, 0, expansion, 0, size);
this.size = size;
}
View on GitHub (pinned to 9b90983fd2)
Solutions
- Ensure the backing array passed to the constructor is at least as large as the maximum size set
- Call ensureSize(size) before setSize to grow the internal array
- Validate size >= 0 before calling
Example fix
// before indexedInts.setSize(values.length); // after indexedInts.ensureSize(values.length); indexedInts.setSize(values.length);
Defensive patterns
Strategy: validation
Validate before calling
if (size >= 0 && size <= expansion.length) { indexed.setSize(size); } Type guard
boolean canSetSize(ArrayBasedIndexedInts v, int size) { return size >= 0 && size <= v.size() || size <= v.inspectArrayCapacity(); } // use documented capacity Try / catch
try { indexed.setSize(size); } catch (IAE e) { indexed.ensureSize(size); indexed.setSize(size); } Prevention
- Call ensureSize before setSize
- Match backing-array allocation to maximum row size
- Clamp sizes to [0, capacity] in reuse/pooling code
When it happens
Trigger: Calling setSize with a negative value or a value larger than the array passed at construction (expansion.length), e.g. from initColumnValues with a bigger row than the allocated array.
Common situations: Reusing a pooled ArrayBasedIndexedInts across rows/columns with mismatched capacities; off-by-one or wrong initial allocation size.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Size[%d] should be between 0 and %d
- Index[%d] >= size[%d]
- Column is not multi-valued
- Not a numeric value type:
- index[%d] >= size[%d] or < 0
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/a0e9837d10c8aac1.
Report an issue: GitHub.