{"record":{"id":"7d2911bda2744b40","repo":"apache/druid","slug":"index-d-size-d-or-0-7d2911","errorCode":null,"errorMessage":"index[%d] >= size[%d] or < 0","messagePattern":"index\\[(.+?)\\] >= size\\[(.+?)\\] or < 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/data/RangeIndexedInts.java","lineNumber":54,"sourceCode":"  public void setSize(int size)\n  {\n    if (size < 0) {\n      throw new IAE(\"Size[%d] must be non-negative\", size);\n    }\n    this.size = size;\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 index;\n  }\n\n  @Override\n  public void inspectRuntimeShape(RuntimeShapeInspector inspector)\n  {\n    // nothing to inspect\n  }\n}\n","sourceCodeStart":36,"sourceCodeEnd":65,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/data/RangeIndexedInts.java#L36-L65","documentation":"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`.","triggerScenarios":"Calling get(i) with i < 0 or i >= the size set via setSize; iterating past the end of the range.","commonSituations":"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.","solutions":["Bound iteration with the RangeIndexedInts' own size()","Fix off-by-one conditions (use i < size())","Validate external indexes against size() before calling get"],"exampleFix":"// before\nfor (int i = 0; i <= range.size(); i++) range.get(i);\n// after\nfor (int i = 0; i < range.size(); i++) range.get(i);","handlingStrategy":"validation","validationCode":"if (i >= 0 && i < range.size()) { int v = range.get(i); }","typeGuard":"boolean valid(RangeIndexedInts r, int i) { return i >= 0 && i < r.size(); }","tryCatchPattern":"try { v = range.get(i); } catch (IllegalArgumentException e) { v = defaultValue; }","preventionTips":["Iterate i from 0 to size()-1","Never mix indexes from different IndexedInts instances"],"tags":["druid","segment","indexing"],"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-17T15:17:12.973Z"}