{"record":{"id":"ca10a558573234ac","repo":"quarkusio/quarkus","slug":"any-can-only-be-used-if-count-is-also-set-ca10a5","errorCode":null,"errorMessage":"ANY can only be used if COUNT is also set","messagePattern":"ANY can only be used if COUNT is also set","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoSearchArgs.java","lineNumber":190,"sourceCode":"    /**\n     * When ANY is provided the command will return as soon as enough matches are found, so the results may not be the\n     * ones closest to the specified point, but on the other hand, the effort invested by the server is significantly\n     * lower.\n     * <p>\n     * Using {@code ANY} requires {@code count} to be set.\n     *\n     * @return the current {@code GeoRadiusArgs}\n     **/\n    public GeoSearchArgs<V> any() {\n        this.any = true;\n        return this;\n    }\n\n    @Override\n    public List<Object> toArgs(Codec codec) {\n        // Validation\n        if (any && count == -1) {\n            throw new IllegalArgumentException(\"ANY can only be used if COUNT is also set\");\n        }\n\n        if (radius > 0 && width > 0) {\n            throw new IllegalArgumentException(\"BYRADIUS and BYBOX cannot be used together\");\n        }\n\n        if (member != null && (latitude != Double.MIN_VALUE || longitude != Double.MIN_VALUE)) {\n            throw new IllegalArgumentException(\"FROMMEMBER and FROMLONLAT cannot be used together\");\n        }\n\n        List<Object> list = new ArrayList<>();\n        if (member != null) {\n            list.add(\"FROMMEMBER\");\n            list.add(new String(codec.encode(member), StandardCharsets.UTF_8));\n        } else {\n            list.add(\"FROMLONLAT\");\n            list.add(Double.toString(longitude));\n            list.add(Double.toString(latitude));","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoSearchArgs.java#L172-L208","documentation":"During toArgs serialization, GeoSearchArgs verifies that the ANY modifier is only combined with COUNT; since Redis requires COUNT for ANY to be valid, the client throws IllegalArgumentException before sending the command. This mirrors the same rule enforced in GeoRadiusStoreArgs.","triggerScenarios":"Building GeoSearchArgs with any() set (or setAny(true)) but never calling count(n), then passing the args to a geosearch call that serializes via toArgs(codec).","commonSituations":"Optimization attempts adding any() for speed without the required COUNT; conditional builders where count() is applied in one branch only; reuse of a shared args template missing count.","solutions":["Call count(n) on the GeoSearchArgs before or after setting any()","Remove any() if COUNT limiting is not wanted","Wrap args construction in a helper that enforces the any+count invariant"],"exampleFix":"// before\nGeoSearchArgs<String> args = GeoSearchArgs.fromMember(\"palermo\")\n    .byRadius(200, GeoUnit.KM)\n    .any();\n// after\nGeoSearchArgs<String> args = GeoSearchArgs.fromMember(\"palermo\")\n    .byRadius(200, GeoUnit.KM)\n    .count(20)\n    .any();","handlingStrategy":"validation","validationCode":"if (args.isAny() && args.getCount() == -1) { throw new IllegalStateException(\"ANY requires COUNT\"); }","typeGuard":null,"tryCatchPattern":"try { geo.geoSearch(key, args); } catch (IllegalArgumentException e) { log.error(\"Invalid geo args: \" + e.getMessage()); }","preventionTips":["Always call count(n) when using any()","Build args in a single helper that enforces the rule","Cover args combinations with unit tests"],"tags":["redis","geo","illegal-argument","argument-validation"],"backgroundTag":"invalid-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"}