apache/druid · error · IllegalArgumentException
Index[%s] < 0
Error message
Index[%s] < 0
What it means
Indexed.checkIndex(int index, int size) is the shared static bounds validator for Indexed implementations: negative indexes throw IAE 'Index[i] < 0'. Like the GenericIndexed variant, it usually indicates an unhandled lookup miss (-1) or index arithmetic underflow.
Source
Thrown at processing/src/main/java/org/apache/druid/segment/data/Indexed.java:124
*/
default boolean isSorted()
{
return false;
}
/**
* Checks if {@code index} is between 0 and {@code size}. Similar to Preconditions.checkElementIndex() except this
* method throws {@link IAE} with custom error message.
* <p>
* Used here to get existing behavior(same error message and exception) of V1 {@link GenericIndexed}.
*
* @param index identifying an element of an {@link Indexed}
* @param size size of the {@link Indexed}
*/
static void checkIndex(int index, int size)
{
if (index < 0) {
throw new IAE("Index[%s] < 0", index);
}
if (index >= size) {
throw new IAE("Index[%d] >= size[%d]", index, size);
}
}
}
View on GitHub (pinned to 9b90983fd2)
Solutions
- Validate lookup results before get(): if (idx < 0) handle-not-found;
- Bound-check externally supplied indexes against size() before access.
- Refactor call sites to use Optional/null-returning lookup helpers instead of sentinel -1.
Example fix
// before Object v = indexed.lookupOrdered(k); return indexed.get(v); // after int idx = indexed.indexOf(k); return idx < 0 ? null : indexed.get(idx);
Defensive patterns
Strategy: type-guard
Validate before calling
if (index < 0 || index >= size) return null;
Type guard
static <T> T safeGet(Indexed<T> idx, int i) { return (i >= 0 && i < idx.size()) ? idx.get(i) : null; } Try / catch
try { return indexed.get(index); } catch (IAE e) { return null; } Prevention
- Convert sentinel -1 lookup results to null/Optional before indexing
- Sanitize numeric inputs before passing them to Indexed.get
- Centralize Indexed access behind a bounds-checked helper
When it happens
Trigger: Any Indexed implementation's get()/accessor delegating to Indexed.checkIndex with a negative index, commonly from indexOf()-style misses returning -1.
Common situations: Treating -1 from a failed lookup as valid, decrementing index 0 to -1, or passing external numeric input straight into get().
Related errors
- Index[%s] < 0
- Index[%d] >= size[%d]
- Column[%d] is not a valid column for segment[%s]
- Column[%d] is not a valid column for the frame based datasou
- Cannot build hash-join matcher on non-key-based condition: %
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/b4ea0c516a0699c3.
Report an issue: GitHub.