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.
Solutions
- Call only .min() or only .max() on a given ZMpopArgs
- Create a new ZMpopArgs per invocation instead of mutating a shared instance
- 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
- Use if/else on a single direction boolean instead of two setters
- Create a new ZMpopArgs per call
- Default the direction explicitly (e.g. MIN) when input is ambiguous
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
- Cannot use LT and GT together
- Cannot use XX and NX together
- Aggregation + aggregate + not supported
- BYRADIUS and BYBOX cannot be used together
- Cannot combine `IDLE` and `TIME`
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/a46f1a5c4df4fcec.
Report an issue: GitHub.
Appendix: 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)