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

  1. Convert all values to a single numeric type (usually Double or Long) before calling add()
  2. Initialize the aggregator with the same type you will feed it
  3. 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

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


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)