redis/jedis · error · UnsupportedAggregationException

requires Boolean, Long, ArrayList , or ArrayList , but got…

Error message

${operationName} requires Boolean, Long, ArrayList<Boolean>, or ArrayList<Long>, but got: ${result.getClass().getName()} and ${input.getClass().getName()}

What it means

LogicalBinaryAggregator.add throws UnsupportedAggregationException when either operand is not one of the supported types: Boolean, Long, ArrayList<Boolean>, or ArrayList<Long>. The aggregator only implements logical combination for these types and rejects everything else.

Solutions

  1. Convert operands to Boolean or Long (or ArrayList<Boolean>/ArrayList<Long>) before calling add()
  2. Use the correct aggregator (Sum, Max, Min) for numeric data instead of LogicalBinaryAggregator
  3. Check the command's Builder to see what Java type it actually returns and map accordingly

Example fix

// before
aggregator.add("true");
// after
aggregator.add(Boolean.parseBoolean("true"));
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(result instanceof Boolean || result instanceof Long || result instanceof ArrayList) ) { throw new IllegalArgumentException("unsupported type for logical aggregation: " + result.getClass()); }

Type guard

boolean isLogicalOperand(Object o) { return o instanceof Boolean || o instanceof Long || (o instanceof ArrayList<?> l && (l.isEmpty() || l.get(0) instanceof Boolean || l.get(0) instanceof Long)); }

Try / catch

try { aggregator.add(value); } catch (UnsupportedAggregationException e) { log.warn("Wrong operand type for AGG logic, converting"); aggregator.add(toLong(value)); }

Prevention

When it happens

Trigger: Calling add() with operands of any other class, e.g. String, Integer, Double, or ArrayList of other element types, after the ArrayList-equal-size check has passed or with non-list types.

Common situations: Passing raw command results (Builder returns Integer/Double/String) into the logical aggregator without converting to Boolean/Long; mixing aggregator types across aggregation policies.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/cedba326d3d7118d. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/executors/aggregators/LogicalBinaryAggregator.java:94

        // ArrayList<Long> treated as boolean
        if (firstExisting instanceof Long && firstNew instanceof Long) {
          ArrayList<Long> res = new ArrayList<>(existingList.size());
          for (int i = 0; i < existingList.size(); i++) {
            boolean e = ((Long) existingList.get(i)) != 0;
            boolean n = ((Long) newList.get(i)) != 0;
            res.add(applyBooleanOp(e, n) ? 1L : 0L);
          }
          result = (T) res;
          return;
        }
      } else {
        // Empty lists → result remains empty list
        result = (T) new ArrayList<>();
        return;
      }
    }

    throw new UnsupportedAggregationException(
        operationName + " requires Boolean, Long, ArrayList<Boolean>, or ArrayList<Long>, but got: "
            + result.getClass().getName() + " and " + input.getClass().getName());
  }

  @Override
  public T getResult() {
    return result;
  }

  /**
   * Template method for subclasses to implement the specific logical operation.
   * @param a first boolean operand
   * @param b second boolean operand
   * @return result of the logical operation
   */
  protected abstract boolean applyBooleanOp(boolean a, boolean b);
}

View on GitHub (pinned to 6dac31d4c2)