quarkusio/quarkus · error · IllegalArgumentException
Cannot set XX and NX together
Error message
Cannot set XX and NX together
What it means
JsonSetArgs builds extra arguments for the JSON.SET command. Redis forbids the XX (only update if exists) and NX (only set if absent) flags together since they are mutually exclusive; the client validates this eagerly in toArgs() and throws IllegalArgumentException before the command is sent. Setting both is always a logic error because the two conditions can never both hold.
Source
Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/JsonSetArgs.java:36
public JsonSetArgs nx() {
this.nx = true;
return this;
}
/**
* Only update elements that already exist. Never add elements.
*
* @return the current {@code GeoaddArgs}
**/
public JsonSetArgs xx() {
this.xx = true;
return this;
}
@Override
public List<Object> toArgs() {
if (xx && nx) {
throw new IllegalArgumentException("Cannot set XX and NX together");
}
List<Object> args = new ArrayList<>();
if (xx) {
args.add("XX");
}
if (nx) {
args.add("NX");
}
return args;
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Call only one of xx() or nx() — decide whether the set should be insert-only (nx) or update-only (xx)
- Validate exclusivity in your own code before building the args if flags come from configuration
- If both semantics are somehow requested, drop the conflicting flag based on your actual intent
Example fix
// before
JsonSetArgs args = new JsonSetArgs().xx().nx(); // throws
// after
JsonSetArgs args = onlyUpdate
? new JsonSetArgs().xx()
: new JsonSetArgs().nx(); Defensive patterns
Strategy: validation
Validate before calling
JsonSetArgs args = new JsonSetArgs();
if (wantInsertOnly && wantUpdateOnly) {
throw new IllegalArgumentException("JSON.SET options XX and NX are mutually exclusive");
}
if (wantInsertOnly) args.nx();
else if (wantUpdateOnly) args.xx(); Try / catch
try {
jsonCommands.jsonSet(key, value, args);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("XX and NX")) {
// fix builder usage: only one flag allowed
}
} Prevention
- Never chain .xx() and .nx() on the same JsonSetArgs
- Centralize JsonSetArgs construction in one helper that enforces exclusivity
- Map config/user flags to at most one of XX/NX at input validation time
When it happens
Trigger: Building JsonSetArgs with a chained/fluent call to both xx() and nx(), e.g. new JsonSetArgs().xx().nx() — often from copy-paste or programmatic assembly where flags are OR-accumulated from booleans/config.
Common situations: Fluent-builder misuse where an extra .nx() is left from a previous variant; mapping user options onto args without validating exclusivity; helper methods that add both flags conditionally.
Related errors
- Only one value from `GT`, `LT` and `NX` can be set
- Cannot use `ON HASH` and `ON JSON` at the same time
- Cannot use descending and ascending order at the same time
- Json array ended without ]
- Control characters not allowed in json string
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/05cc6ce1687cb662.
Report an issue: GitHub.