{"record":{"id":"87e834c86ff984ac","repo":"apache/druid","slug":"index-d-size-d-or-0","errorCode":null,"errorMessage":"index[%d] >= size[%d] or < 0","messagePattern":"index\\[(.+?)\\] >= size\\[(.+?)\\] or < 0","errorType":"exception","errorClass":"IAE","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/data/ArrayBasedIndexedInts.java","lineNumber":91,"sourceCode":"    this.size = size;\n  }\n\n  public void setValue(int index, int value)\n  {\n    expansion[index] = value;\n  }\n\n  @Override\n  public int size()\n  {\n    return size;\n  }\n\n  @Override\n  public int get(int index)\n  {\n    if (index < 0 || index >= size) {\n      throw new IAE(\"index[%d] >= size[%d] or < 0\", index, size);\n    }\n    return expansion[index];\n  }\n\n  @Override\n  public void inspectRuntimeShape(RuntimeShapeInspector inspector)\n  {\n    // nothing to inspect\n  }\n}\n","sourceCodeStart":73,"sourceCodeEnd":102,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/data/ArrayBasedIndexedInts.java#L73-L102","documentation":"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.","triggerScenarios":"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.","commonSituations":"Iterating with the backing array length instead of size(); reusing a resized ArrayBasedIndexedInts with old indexes; concurrent modification during iteration.","solutions":["Iterate using size() as the exclusive upper bound","Re-read size() after any resize/setValues call","Ensure index >= 0 before calling get"],"exampleFix":"// before\nfor (int i = 0; i < arr.length; i++) { int v = indexed.get(i); }\n// after\nfor (int i = 0; i < indexed.size(); i++) { int v = indexed.get(i); }","handlingStrategy":"validation","validationCode":"if (index >= 0 && index < indexed.size()) { int v = indexed.get(index); }","typeGuard":"boolean inRange(IndexedInts v, int i) { return i >= 0 && i < v.size(); }","tryCatchPattern":"try { return indexed.get(index); } catch (IAE e) { return Indexable.NOT_FOUND; }","preventionTips":["Always bound loops by size(), never by array length","Re-fetch size() after any mutation","Use indexed iteration (iterator()) instead of manual index math where possible"],"tags":["java","index-out-of-bounds","segments"],"backgroundTag":"index-out-of-bounds","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}