{"record":{"id":"254f63e3af9d369d","repo":"quarkusio/quarkus","slug":"cannot-use-withlabels-and-selected-labels-toget","errorCode":null,"errorMessage":"Cannot use `WITHLABELS` and `SELECTED_LABELS together","messagePattern":"Cannot use `WITHLABELS` and `SELECTED_LABELS together","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/timeseries/MGetArgs.java","lineNumber":72,"sourceCode":"        selectedLabels.add(nonNull(label, \"label\"));\n        return this;\n    }\n\n    @Override\n    public List<Object> toArgs() {\n        List<Object> list = new ArrayList<>();\n        if (latest) {\n            list.add(\"LATEST\");\n        }\n        if (withLabels) {\n            list.add(\"WITHLABELS\");\n        }\n        if (!selectedLabels.isEmpty()) {\n            list.add(\"SELECTED_LABELS\");\n            list.addAll(selectedLabels);\n        }\n        if (withLabels && !selectedLabels.isEmpty()) {\n            throw new IllegalArgumentException(\"Cannot use `WITHLABELS` and `SELECTED_LABELS together\");\n        }\n\n        return list;\n    }\n}\n","sourceCodeStart":54,"sourceCodeEnd":78,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/timeseries/MGetArgs.java#L54-L78","documentation":"MGetArgs.toArgs() builds the TS.MGET command argument list for RedisTimeSeries. The RedisTimeSeries protocol forbids combining WITHLABELS with SELECTED_LABELS (the latter already returns selected labels), so the builder rejects the mutually exclusive combination when serializing. Note the error occurs at toArgs() time, not when the setters were called.","triggerScenarios":"Calling mgetArgs.withLabels(true) (or the WITHLABELS setter) and also .selectedLabels(\"a\",\"b\") on the same MRangeArgs/MGetArgs instance, then invoking toArgs() when sending the command.","commonSituations":"Conditional building code where one branch sets WITHLABELS and another adds selected labels; reusing a shared args object across calls; copying example code that sets both options.","solutions":["Remove the selectedLabels(...) call if you want all labels (WITHLABELS)","Remove the withLabels(true) call if you only need specific labels via selectedLabels(...)","If args are built conditionally, make the two options mutually exclusive branches"],"exampleFix":"// before\nMGetArgs args = MGetArgs.Builder.getInstance()\n    .withLabels(true)\n    .selectedLabels(\"sensor\", \"location\");\n// after\nMGetArgs args = MGetArgs.Builder.getInstance()\n    .selectedLabels(\"sensor\", \"location\");","handlingStrategy":"validation","validationCode":"if (withLabels && selectedLabels != null && !selectedLabels.isEmpty()) {\n    throw new IllegalArgumentException(\"Use either WITHLABELS or SELECTED_LABELS, not both\");\n}","typeGuard":"boolean isExclusiveValid(boolean withLabels, java.util.List<String> selected) {\n    return !withLabels || selected == null || selected.isEmpty();\n}","tryCatchPattern":"try {\n    redis.ts().mget(args);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"WITHLABELS\")) {\n        args = rebuildWithoutWithLabels();\n    }\n}","preventionTips":["Decide the label strategy once (all labels vs selected) before building args","Build args in a single code path, not merged conditional branches","Wrap arg construction in a helper that enforces exclusivity"],"tags":["java","redis","redis-timeseries","mutually-exclusive-arguments"],"backgroundTag":"incompatible-argument-combination","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"}