redis/jedis · error · UnsupportedAggregationException
SumAggregator requires numeric types of the same kind…
Error message
SumAggregator requires numeric types of the same kind (Integer, Long, Double), but got: ${sum.getClass().getSimpleName()} and ${value.getClass().getSimpleName()} What it means
SumAggregator.add throws UnsupportedAggregationException when the operands are not the same numeric kind among Integer, Long, and Double (e.g. mixing Long and Double, or passing non-numeric types). Mixed-kind addition is rejected to avoid silent precision loss.
Solutions
- Convert all values to a single numeric type (usually Double or Long) before calling add()
- Initialize the aggregator with the same type you will feed it
- Use a builder that returns Integer/Long/Double for the aggregated commands
Example fix
// before sumAgg.add(1.5); // sum is Long // after sumAgg.add(Double.valueOf(1.5)); // with sum initialized as Double, or add Long value instead
Defensive patterns
Strategy: validation
Validate before calling
if (!(value instanceof Integer || value instanceof Long || value instanceof Double)) { throw new IllegalArgumentException("SumAggregator needs Integer/Long/Double"); } Type guard
boolean isSummable(Number n) { return n instanceof Integer || n instanceof Long || n instanceof Double; } Try / catch
try { sumAgg.add(value); } catch (UnsupportedAggregationException e) { sumAgg = new SumAggregator<>(Double.class); sumAgg.add(((Number) value).doubleValue()); } Prevention
- Pick one numeric type for the whole aggregation and convert inputs to it
- Check the return type (Builder) of the commands being summed
- Never mix Float/BigDecimal into SumAggregator; convert to Double first
When it happens
Trigger: Calling add() with a value whose type differs from the accumulated sum (Long sum + Double value), or with a non-supported numeric/numeric-like type such as BigDecimal, Float, or String.
Common situations: Aggregating results from commands that return Double (e.g. ZSCORE) with results returning Long (e.g. INCR); feeding Float or BigInteger results from custom builders.
Related errors
- AGG_SUM policy requires numeric type, but got
- DEFAULT policy requires List, Set, Map, JedisByteHashMap…
- requires Boolean, Long, ArrayList , or ArrayList , but got
- requires Boolean, Long, ArrayList , or ArrayList , but got…
- AGG_MAX policy requires Comparable types or KeyValue, but…
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/a849bd0ae732b53f.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/executors/aggregators/SumAggregator.java:31
@Override
public void add(T value) {
if (value == null) {
return;
}
if (sum == null) {
sum = value;
return;
}
if (sum instanceof Long && value instanceof Long) {
sum = (T) Long.valueOf(sum.longValue() + value.longValue());
} else if (sum instanceof Integer && value instanceof Integer) {
sum = (T) Integer.valueOf(sum.intValue() + value.intValue());
} else if (sum instanceof Double && value instanceof Double) {
sum = (T) Double.valueOf(sum.doubleValue() + value.doubleValue());
} else {
throw new UnsupportedAggregationException(
"SumAggregator requires numeric types of the same kind (Integer, Long, Double), but got: "
+ sum.getClass().getSimpleName() + " and " + value.getClass().getSimpleName());
}
}
@Override
public T getResult() {
return sum;
}
}
View on GitHub (pinned to 6dac31d4c2)