{"record":{"id":"7ec2056128cdae06","repo":"quarkusio/quarkus","slug":"cannot-use-lt-and-gt-together","errorCode":null,"errorMessage":"Cannot use LT and GT together","messagePattern":"Cannot use LT and GT together","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/sortedset/ZAddArgs.java","lineNumber":77,"sourceCode":"\n    /**\n     * Only update existing elements if the new score is greater than the current score.\n     * This flag doesn't prevent adding new elements.\n     *\n     * @return the current {@code ZAddArgs}\n     **/\n    public ZAddArgs gt() {\n        this.gt = true;\n        return this;\n    }\n\n    @Override\n    public List<Object> toArgs() {\n        if (xx && nx) {\n            throw new IllegalArgumentException(\"Cannot use XX and NX together\");\n        }\n        if (lt && gt) {\n            throw new IllegalArgumentException(\"Cannot use LT and GT together\");\n        }\n\n        List<Object> args = new ArrayList<>();\n        putFlag(args, nx, \"NX\");\n        putFlag(args, xx, \"XX\");\n        putFlag(args, lt, \"LT\");\n        putFlag(args, gt, \"GT\");\n        putFlag(args, ch, \"CH\");\n        return args;\n    }\n\n    public void putFlag(List<Object> args, boolean value, String flag) {\n        if (value) {\n            args.add(flag);\n        }\n    }\n}\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/sortedset/ZAddArgs.java#L59-L95","documentation":"ZADD's LT (update only if lower score) and GT (update only if greater score) modifiers are mutually exclusive in Redis. ZAddArgs.toArgs() throws IllegalArgumentException when both boolean flags are set, because the resulting command would be rejected by the server.","triggerScenarios":"Chaining .lt().gt() (or calling both setters) on ZAddArgs before a zadd call.","commonSituations":"Choosing comparison direction from config/user input where the variable can end up 'both'; reusing a mutated ZAddArgs across calls.","solutions":["Keep only .lt() or only .gt() depending on desired update direction","Reset or recreate ZAddArgs when the comparison mode changes","Guard with an if/else so only one flag is ever set"],"exampleFix":"// before\nZAddArgs args = new ZAddArgs().lt().gt();\n// after\nZAddArgs args = new ZAddArgs().lt(); // lower-than-only updates","handlingStrategy":"validation","validationCode":"if (lowerThan && greaterThan) throw new IllegalArgumentException(\"Choose LT or GT for ZADD, not both\");","typeGuard":null,"tryCatchPattern":"try {\n    sortedSet.zadd(key, score, member, args);\n} catch (IllegalArgumentException e) {\n    // reset args with only lt or gt\n}","preventionTips":["Derive lt/gt from a single direction variable: if (desc) lt else gt","Recreate ZAddArgs when comparison mode changes","Test builder combinations that reflect real call paths"],"tags":["redis","sorted-set","mutually-exclusive-options","zadd"],"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-14T00:17:10.932Z"}