{"record":{"id":"a849bd0ae732b53f","repo":"redis/jedis","slug":"sumaggregator-requires-numeric-types-of-the-same-k","errorCode":null,"errorMessage":"SumAggregator requires numeric types of the same kind (Integer, Long, Double), but got: ${sum.getClass().getSimpleName()} and ${value.getClass().getSimpleName()}","messagePattern":"SumAggregator requires numeric types of the same kind \\(Integer, Long, Double\\), but got: (.+?) and (.+?)","errorType":"exception","errorClass":"UnsupportedAggregationException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/executors/aggregators/SumAggregator.java","lineNumber":31,"sourceCode":"  @Override\n  public void add(T value) {\n    if (value == null) {\n      return;\n    }\n\n    if (sum == null) {\n      sum = value;\n      return;\n    }\n\n    if (sum instanceof Long && value instanceof Long) {\n      sum = (T) Long.valueOf(sum.longValue() + value.longValue());\n    } else if (sum instanceof Integer && value instanceof Integer) {\n      sum = (T) Integer.valueOf(sum.intValue() + value.intValue());\n    } else if (sum instanceof Double && value instanceof Double) {\n      sum = (T) Double.valueOf(sum.doubleValue() + value.doubleValue());\n    } else {\n      throw new UnsupportedAggregationException(\n          \"SumAggregator requires numeric types of the same kind (Integer, Long, Double), but got: \"\n              + sum.getClass().getSimpleName() + \" and \" + value.getClass().getSimpleName());\n    }\n  }\n\n  @Override\n  public T getResult() {\n    return sum;\n  }\n}\n","sourceCodeStart":13,"sourceCodeEnd":42,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/executors/aggregators/SumAggregator.java#L13-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nsumAgg.add(1.5); // sum is Long\n// after\nsumAgg.add(Double.valueOf(1.5)); // with sum initialized as Double, or add Long value instead","handlingStrategy":"validation","validationCode":"if (!(value instanceof Integer || value instanceof Long || value instanceof Double)) { throw new IllegalArgumentException(\"SumAggregator needs Integer/Long/Double\"); }","typeGuard":"boolean isSummable(Number n) { return n instanceof Integer || n instanceof Long || n instanceof Double; }","tryCatchPattern":"try { sumAgg.add(value); } catch (UnsupportedAggregationException e) { sumAgg = new SumAggregator<>(Double.class); sumAgg.add(((Number) value).doubleValue()); }","preventionTips":["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"],"tags":["aggregation","numeric","type-mismatch","sum"],"backgroundTag":"dtype-mismatch","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}