apache/druid · error · IllegalArgumentException
Size[%d] must be non-negative
Error message
Size[%d] must be non-negative
What it means
Validation guard on the reusable RangeIndexedInts setter: setSize is meant to configure the reusable [0..N-1] sequence before use, and a negative size would make size()/get() nonsensical. It fires when a cursor factory or test helper (getRow, mockSelectors) configures the reusable instance with a negative row size, which would indicate a corrupted row-length source or a misconfigured selector; the row size handed to the cursor must be >= 0.
Source
Thrown at processing/src/main/java/org/apache/druid/segment/data/RangeIndexedInts.java:39
import org.apache.druid.java.util.common.IAE;
import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector;
/**
* Reusable IndexedInts that returns sequences [0, 1, ..., N].
*/
public class RangeIndexedInts implements IndexedInts
{
private int size;
public RangeIndexedInts()
{
}
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;
}View on GitHub (pinned to 9b90983fd2)
Solutions
- Clamp or validate the computed row count to >= 0 before calling setSize
- Fix the upstream computation that produced the negative size (e.g. max(0, end - start))
- If this comes from getRow(), check the cursor's range/end offsets for overflow
Example fix
// before rangeIndexedInts.setSize(end - start); // after rangeIndexedInts.setSize(Math.max(0, end - start));
Defensive patterns
Strategy: validation
Validate before calling
int size = end - start; if (size < 0) size = 0; rangeIndexedInts.setSize(size);
Prevention
- Clamp computed sizes with Math.max(0, ...)
- Audit cursor offset arithmetic for negative results
- Validate mock sizes in tests
When it happens
Trigger: Calling setSize(n) with a negative n, typically from a row-holder (getRow) that copied a negative row count from an upstream source or from mock selectors in tests.
Common situations: Cursor/row arithmetic producing a negative count when reading near the end of a segment; test mocks wired with bad sizes.
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
- Query type '%s' does not support returning results as arrays
- Unknown type[%s] for metric[%s]
- Cannot operate on a dimension with no dictionary
- Cannot operate on a dimension with unknown cardinality
- Null cursor factory found. Probably trying to issue a query
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/d84f6214d1f6c317.
Report an issue: GitHub.