quarkusio/quarkus · error · IllegalArgumentException

Cannot use MIN and MAX together

Error message

Cannot use MIN and MAX together

What it means

ZMPOPFROM... wait — ZMpopArgs models the MIN/MAX modifier of the ZMPOP command: pop the element with the lowest or highest score. Redis allows only one direction per call, so the library throws IllegalArgumentException in toArgs() if both flags are set.

Source

Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/sortedset/ZMpopArgs.java:50

        this.max = true;
        return this;
    }

    /**
     * The optional {@code COUNT} can be used to specify the number of elements to pop, and is set to 1 by default.
     *
     * @param count the count value
     * @return the current {@code ZmpopArgs}
     **/
    public ZMpopArgs count(int count) {
        this.count = count;
        return this;
    }

    @Override
    public List<Object> toArgs() {
        if (min && max) {
            throw new IllegalArgumentException("Cannot use MIN and MAX together");
        }

        List<Object> args = new ArrayList<>();
        if (min) {
            args.add("MIN");
        }
        if (max) {
            args.add("MAX");
        }

        if (count > 0) {
            args.add("COUNT");
            args.add(Integer.toString(count));
        }

        return args;
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Call only .min() or only .max() on a given ZMpopArgs
  2. Create a new ZMpopArgs per invocation instead of mutating a shared instance
  3. Ensure the direction code path is if/else, not two independent ifs

Example fix

// before
ZMpopArgs args = new ZMpopArgs().min().max();
// after
ZMpopArgs args = new ZMpopArgs().min(); // or .max()
Defensive patterns

Strategy: validation

Validate before calling

if (wantMin == wantMax) throw new IllegalArgumentException("ZMPOP direction must be exactly one of MIN/MAX");

Try / catch

try {
    sortedSet.zmpop(keys, args);
} catch (IllegalArgumentException e) {
    // rebuild ZMpopArgs with one direction
}

Prevention

When it happens

Trigger: Chaining .min().max() on ZMpopArgs (or setting both booleans via separate code paths) before executing the zmpop command.

Common situations: Direction chosen dynamically (e.g. from config or a 'descending' flag) but both setters invoked; builder reuse across calls with different directions.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/a46f1a5c4df4fcec. Report an issue: GitHub.