{"record":{"id":"49204205d3b5d5c1","repo":"quarkusio/quarkus","slug":"only-one-value-from-gt-lt-and-nx-can-be-set","errorCode":null,"errorMessage":"Only one value from `GT`, `LT` and `NX` can be set","messagePattern":"Only one value from `GT`, `LT` and `NX` can be set","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/keys/ExpireArgs.java","lineNumber":71,"sourceCode":"    public ExpireArgs gt() {\n        this.gt = true;\n        return this;\n    }\n\n    public List<Object> toArgs() {\n        List<Object> args = new ArrayList<>();\n\n        boolean exclusion = false;\n        if (nx) {\n            args.add(\"NX\");\n            exclusion = true;\n        }\n        if (xx) {\n            args.add(\"XX\");\n        }\n        if (lt) {\n            if (exclusion) {\n                throw new IllegalArgumentException(\"Only one value from `GT`, `LT` and `NX` can be set\");\n            }\n            exclusion = true;\n            args.add(\"LT\");\n        }\n        if (gt) {\n            if (exclusion) {\n                throw new IllegalArgumentException(\"Only one value from `GT`, `LT` and `NX` can be set\");\n            }\n            args.add(\"GT\");\n        }\n        return args;\n    }\n}\n","sourceCodeStart":53,"sourceCodeEnd":85,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/keys/ExpireArgs.java#L53-L85","documentation":"ExpireArgs builds extra arguments for EXPIRE/PEXPIRE/EXPIREAT/PEXPIREAT. Redis allows at most one of the NX, GT, LT exclusion conditions per call; the client detects two or more of these flags (here NX combined with LT, or LT combined with GT) in toArgs() and throws IllegalArgumentException before sending the command. XX is tracked separately and not part of this check.","triggerScenarios":"Chaining multiple exclusion flags on ExpireArgs, e.g. new ExpireArgs().nx().lt() or .lt().gt(), then passing it to a keys datasource _pexpireat/_expire call.","commonSituations":"Accumulating expiry options from config or user input where more than one of nx/gt/lt is enabled; copy-pasted builder chains; generic option-mapping code that applies every non-default flag.","solutions":["Keep at most one of nx(), gt(), or lt() on the ExpireArgs instance","Validate your option set before constructing ExpireArgs if flags come from external input","XX may be combined with one exclusion flag — if you need XX, keep it and drop the extra exclusions","Choose the intended precedence (e.g. prefer nx over lt) and build only that flag"],"exampleFix":"// before\nExpireArgs args = new ExpireArgs().nx().lt(); // throws\n// after\nExpireArgs args = new ExpireArgs().lt(); // only one of NX/GT/LT\n// or with XX if allowed:\nExpireArgs args2 = new ExpireArgs().xx().lt();","handlingStrategy":"validation","validationCode":"int exclusions = (useNx ? 1 : 0) + (useGt ? 1 : 0) + (useLt ? 1 : 0);\nif (exclusions > 1) {\n    throw new IllegalArgumentException(\"At most one of NX, GT, LT may be set for EXPIRE\");\n}\nExpireArgs args = new ExpireArgs();\nif (useXx) args.xx();\nif (useNx) args.nx();\nelse if (useGt) args.gt();\nelse if (useLt) args.lt();","typeGuard":null,"tryCatchPattern":"try {\n    keys.pexpireat(key, timestamp, args);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"GT`, `LT` and `NX\")) {\n        // rebuild ExpireArgs with a single exclusion flag\n    }\n}","preventionTips":["Count nx/gt/lt flags before building ExpireArgs; allow at most one","Remember XX can be combined with one of NX/GT/LT but never two exclusions","Centralize expiry-args construction in a utility that validates flag combinations"],"tags":["redis","illegalargument","keys","expire","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"}