{"record":{"id":"0f501303a6626d23","repo":"quarkusio/quarkus","slug":"any-can-only-be-used-if-count-is-also-set","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/GeoRadiusArgs.java","lineNumber":107,"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 GeoRadiusArgs any() {\n        this.any = true;\n        return this;\n    }\n\n    @Override\n    public List<Object> toArgs() {\n        // Validation\n        if (any && count == -1) {\n            throw new IllegalArgumentException(\"ANY can only be used if COUNT is also set\");\n        }\n\n        List<Object> list = new ArrayList<>();\n        if (withDistance) {\n            list.add(\"WITHDIST\");\n        }\n        if (withCoordinates) {\n            list.add(\"WITHCOORD\");\n        }\n        if (withHash) {\n            list.add(\"WITHHASH\");\n        }\n\n        if (count > 0) {\n            list.add(\"COUNT\");\n            list.add(Long.toString(count));\n        }\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoRadiusArgs.java#L89-L125","documentation":"GeoRadiusArgs.toArgs() validates that the ANY option (return any close-enough members instead of the nearest) is only meaningful together with COUNT. Redis rejects ANY without COUNT, so the library throws this IllegalArgumentException before sending the GEORADIUS/GEORADIUSBYMEMBER command.","triggerScenarios":"Calling geoRadiusArgs.any() without a preceding count(n) on the same args object, then passing it to georadius/georadiusbymember; also when any() is set from a flag but the count value was never configured (left at the internal default -1).","commonSituations":"Config with an enabled 'useAny' flag but no count property; fluent chains copied from examples that included any() but dropped count(); building options conditionally where count() is skipped by a branch.","solutions":["Always chain count(n) when using any(): GeoRadiusArgs.Builder.geoRadiusArgs().count(10).any().","If ANY is set from config, only apply it when a count value is also configured; otherwise drop any().","Remove any() if the query does not limit results."],"exampleFix":"// before\nGeoRadiusArgs args = GeoRadiusArgs.Builder.geoRadiusArgs().any(); // throws in toArgs\n// after\nGeoRadiusArgs args = GeoRadiusArgs.Builder.geoRadiusArgs().count(10).any();","handlingStrategy":"validation","validationCode":"GeoRadiusArgs.Builder b = GeoRadiusArgs.Builder.geoRadiusArgs();\nif (useAny) {\n    if (count <= 0) throw new IllegalArgumentException(\"ANY requires COUNT>0\");\n    b.count(count).any();\n} else if (count > 0) {\n    b.count(count);\n}","typeGuard":null,"tryCatchPattern":"try { return geo.georadius(key, lon, lat, dist, unit, args); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"ANY can only be used if COUNT\")) { args.count(10).any(); return geo.georadius(key, lon, lat, dist, unit, args); } throw e; }","preventionTips":["Treat any() as an add-on to count(n), never a standalone option.","When any() comes from config, require the count property to also be present and positive.","Centralize GeoRadiusArgs construction in one helper that enforces the ANY+COUNT pairing."],"tags":["redis","geo","mutually-dependent-options"],"backgroundTag":"conflicting-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"}