apache/druid · error · IAE

index[ ] >= size[ ] or < 0

Error message

index[%d] >= size[%d] or < 0

What it means

ArrayBasedIndexedInts.get(int) bounds-checks the index against the current active size, throwing IAE when the index is negative or >= size. The expansion array may be larger than the active size, so checking against size (not array length) preserves semantics.

Solutions

  1. Iterate using size() as the exclusive upper bound
  2. Re-read size() after any resize/setValues call
  3. Ensure index >= 0 before calling get

Example fix

// before
for (int i = 0; i < arr.length; i++) { int v = indexed.get(i); }
// after
for (int i = 0; i < indexed.size(); i++) { int v = indexed.get(i); }
Defensive patterns

Strategy: validation

Validate before calling

if (index >= 0 && index < indexed.size()) { int v = indexed.get(index); }

Type guard

boolean inRange(IndexedInts v, int i) { return i >= 0 && i < v.size(); }

Try / catch

try { return indexed.get(index); } catch (IAE e) { return Indexable.NOT_FOUND; }

Prevention

When it happens

Trigger: Calling get(index) with index < 0 or index >= size on an IndexedInts, typically from row-iteration code using a stale size or wrong loop bound.

Common situations: Iterating with the backing array length instead of size(); reusing a resized ArrayBasedIndexedInts with old indexes; concurrent modification during iteration.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/87e834c86ff984ac. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/segment/data/ArrayBasedIndexedInts.java:91

    this.size = size;
  }

  public void setValue(int index, int value)
  {
    expansion[index] = value;
  }

  @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 expansion[index];
  }

  @Override
  public void inspectRuntimeShape(RuntimeShapeInspector inspector)
  {
    // nothing to inspect
  }
}

View on GitHub (pinned to 9b90983fd2)