redis/jedis · error · UnsupportedAggregationException

requires ArrayLists of equal size, but got sizes: and

Error message

${operationName} requires ArrayLists of equal size, but got sizes: ${existingList.size()} and ${newList.size()}

What it means

LogicalBinaryAggregator.add throws UnsupportedAggregationException when both operands are ArrayLists but their sizes differ. Logical aggregation (AND/OR style) combines elements pairwise, which is only defined for equal-length lists. The library refuses to guess how to pad or truncate.

Solutions

  1. Ensure all lists fed into the logical aggregator have the same number of elements before calling add()
  2. Verify the source commands produced complete results (no missing keys, no partial reads)
  3. If lengths can legitimately differ, handle the mismatch in caller code instead of using this aggregator

Example fix

// before
aggregator.add(listA); // size 3
aggregator.add(listB); // size 2 -> throws
// after
if (listB.size() == listA.size()) { aggregator.add(listB); } else { throw new IllegalStateException("size mismatch upstream"); }
Defensive patterns

Strategy: validation

Validate before calling

if (listA.size() != listB.size()) { throw new IllegalArgumentException("lists must have equal size before logical aggregation"); }

Type guard

boolean sameSize(List<?> a, List<?> b) { return a != null && b != null && a.size() == b.size(); }

Try / catch

try { aggregator.add(input); } catch (UnsupportedAggregationException e) { log.error("List size mismatch: {}", e.getMessage()); throw new IllegalStateException("upstream produced unequal list sizes", e); }

Prevention

When it happens

Trigger: Calling add() twice on a LogicalBinaryAggregator whose current result is an ArrayList and whose input is an ArrayList of a different length, e.g. aggregating two command outputs that returned different numbers of elements.

Common situations: Pipelined or multi-key responses where one key returned fewer elements than another; aggregating partial results after a key was deleted or expired between calls.

Related errors


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

Appendix: source

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

      result = (T) Boolean.valueOf(applyBooleanOp((Boolean) result, (Boolean) input));
      return;
    }

    // Handle Long
    if (result instanceof Long && input instanceof Long) {
      boolean existingBool = (Long) result != 0;
      boolean newBool = (Long) input != 0;
      result = (T) Long.valueOf(applyBooleanOp(existingBool, newBool) ? 1L : 0L);
      return;
    }

    // Handle ArrayList
    if (result instanceof ArrayList && input instanceof ArrayList) {
      ArrayList<?> existingList = (ArrayList<?>) result;
      ArrayList<?> newList = (ArrayList<?>) input;

      if (existingList.size() != newList.size()) {
        throw new UnsupportedAggregationException(
            operationName + " requires ArrayLists of equal size, but got sizes: "
                + existingList.size() + " and " + newList.size());
      }

      if (!existingList.isEmpty()) {
        Object firstExisting = existingList.get(0);
        Object firstNew = newList.get(0);

        // ArrayList<Boolean>
        if (firstExisting instanceof Boolean && firstNew instanceof Boolean) {
          ArrayList<Boolean> res = new ArrayList<>(existingList.size());
          for (int i = 0; i < existingList.size(); i++) {
            res.add(applyBooleanOp((Boolean) existingList.get(i), (Boolean) newList.get(i)));
          }
          result = (T) res;
          return;
        }

View on GitHub (pinned to 6dac31d4c2)