apache/druid · error · IllegalStateException
Cannot return double for Null Value
Error message
Cannot return double for Null Value
What it means
NullableNumericAggregator throws this IllegalStateException from getDouble() when the aggregated result is null (isNullResult == true). Druid models null numerics explicitly; returning NaN or 0.0 would be ambiguous, so callers must check isNull() first.
Source
Thrown at processing/src/main/java/org/apache/druid/query/aggregation/NullableNumericAggregator.java:101
throw new IllegalStateException("Cannot return float for Null Value");
}
return delegate.getFloat();
}
@Override
public long getLong()
{
if (isNullResult) {
throw new IllegalStateException("Cannot return long for Null Value");
}
return delegate.getLong();
}
@Override
public double getDouble()
{
if (isNullResult) {
throw new IllegalStateException("Cannot return double for Null Value");
}
return delegate.getDouble();
}
@Override
public boolean isNull()
{
return isNullResult || delegate.isNull();
}
@Override
public void close()
{
delegate.close();
}
}
View on GitHub (pinned to 9b90983fd2)
Solutions
- Guard with agg.isNull() before calling getDouble()
- Confirm the query targets the right column and segments actually contain non-null data
- Check that the nullable wrapper is being used with a null-aware metric factory as intended
- If results should never be null, coalesce the input (e.g., use a nullToDefault expression or filter nulls)
Example fix
// before double v = agg.getDouble(); // after double v = agg.isNull() ? 0.0d /* or handle null */ : agg.getDouble();
Defensive patterns
Strategy: type-guard
Validate before calling
if (agg.isNull()) {
return null;
} Type guard
Double value = agg.isNull() ? null : agg.getDouble();
Try / catch
try {
return agg.getDouble();
} catch (IllegalStateException e) {
if (e.getMessage().contains("Cannot return double for Null Value")) {
return null;
}
throw e;
} Prevention
- Use isNull() as the gate before getDouble()
- Prefer boxed results or Optional in extraction layers to carry nullability
- Coalesce nulls in the query itself (expressions/filters) when a numeric default is acceptable
- Cover null-heavy data in aggregation unit tests
When it happens
Trigger: Calling getDouble() on an aggregator whose underlying aggregation saw only null values during init/aggregate lifecycle.
Common situations: Double aggregations (doubleSum, doubleMin/Max, doubleFirst/Last, average) over all-null or missing columns; custom extraction code bypassing the null check; post-aggregator code reading raw aggregator state.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Cannot return float for Null Value
- Cannot return long for Null Value
- Cannot return float for Null Value
- Cannot return long for Null Value
- Cannot return double for Null Value
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/fcea13b82898d470.
Report an issue: GitHub.