{"record":{"id":"05cc6ce1687cb662","repo":"quarkusio/quarkus","slug":"cannot-set-xx-and-nx-together-05cc6c","errorCode":null,"errorMessage":"Cannot set XX and NX together","messagePattern":"Cannot set XX and NX together","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/JsonSetArgs.java","lineNumber":36,"sourceCode":"    public JsonSetArgs nx() {\n        this.nx = true;\n        return this;\n    }\n\n    /**\n     * Only update elements that already exist. Never add elements.\n     *\n     * @return the current {@code GeoaddArgs}\n     **/\n    public JsonSetArgs xx() {\n        this.xx = true;\n        return this;\n    }\n\n    @Override\n    public List<Object> toArgs() {\n        if (xx && nx) {\n            throw new IllegalArgumentException(\"Cannot set XX and NX together\");\n        }\n        List<Object> args = new ArrayList<>();\n        if (xx) {\n            args.add(\"XX\");\n        }\n        if (nx) {\n            args.add(\"NX\");\n        }\n        return args;\n    }\n}\n","sourceCodeStart":18,"sourceCodeEnd":48,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/JsonSetArgs.java#L18-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nJsonSetArgs args = new JsonSetArgs().xx().nx(); // throws\n// after\nJsonSetArgs args = onlyUpdate\n    ? new JsonSetArgs().xx()\n    : new JsonSetArgs().nx();","handlingStrategy":"validation","validationCode":"JsonSetArgs args = new JsonSetArgs();\nif (wantInsertOnly && wantUpdateOnly) {\n    throw new IllegalArgumentException(\"JSON.SET options XX and NX are mutually exclusive\");\n}\nif (wantInsertOnly) args.nx();\nelse if (wantUpdateOnly) args.xx();","typeGuard":null,"tryCatchPattern":"try {\n    jsonCommands.jsonSet(key, value, args);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"XX and NX\")) {\n        // fix builder usage: only one flag allowed\n    }\n}","preventionTips":["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"],"tags":["redis","illegalargument","json","mutually-exclusive-args"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}