apache/druid · error · IllegalArgumentException
index[ ] >= size[ ] or < 0
Error message
index[%d] >= size[%d] or < 0
What it means
RangeIndexedInts.get(index) returns the index itself (values are 0..size-1), so any index outside [0, size) is invalid and throws this IAE. The message text is slightly misleading but the condition is `index < 0 || index >= size`.
Solutions
- Bound iteration with the RangeIndexedInts' own size()
- Fix off-by-one conditions (use i < size())
- Validate external indexes against size() before calling get
Example fix
// before for (int i = 0; i <= range.size(); i++) range.get(i); // after for (int i = 0; i < range.size(); i++) range.get(i);
Defensive patterns
Strategy: validation
Validate before calling
if (i >= 0 && i < range.size()) { int v = range.get(i); } Type guard
boolean valid(RangeIndexedInts r, int i) { return i >= 0 && i < r.size(); } Try / catch
try { v = range.get(i); } catch (IllegalArgumentException e) { v = defaultValue; } Prevention
- Iterate i from 0 to size()-1
- Never mix indexes from different IndexedInts instances
When it happens
Trigger: Calling get(i) with i < 0 or i >= the size set via setSize; iterating past the end of the range.
Common situations: Off-by-one loops over row values; using indexes from a different column's cardinality; stale size after setSize was called with a smaller value.
Related errors
- != 0
- Index[ ] >= size[ ]
- Index[ ] >= size[ ] or < 0
- Actual Row count mismatch. Expected
- Attempt to add row to swapped-out sink for segment
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/7d2911bda2744b40.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/segment/data/RangeIndexedInts.java:54
public void setSize(int size)
{
if (size < 0) {
throw new IAE("Size[%d] must be non-negative", size);
}
this.size = size;
}
@Override
public int size()
{
return size;
}
@Override
public int get(int index)
{
if (index < 0 || index >= size) {
throw new IAE("index[%d] >= size[%d] or < 0", index, size);
}
return index;
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
// nothing to inspect
}
}
View on GitHub (pinned to 9b90983fd2)