{"record":{"id":"59bdc50af21fcc50","repo":"quarkusio/quarkus","slug":"any-can-only-be-used-if-count-is-also-set-59bdc5","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/GeoSearchStoreArgs.java","lineNumber":152,"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 GeoSearchStoreArgs}\n     **/\n    public GeoSearchStoreArgs<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":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoSearchStoreArgs.java#L134-L170","documentation":"In GeoSearchStoreArgs.toArgs(), the ANY option is only valid in Redis when paired with COUNT. If any=true was set but no count was provided (count == -1), the library throws IllegalArgumentException to prevent sending an invalid GEOSEARCHSTORE command.","triggerScenarios":"Calling any() (or any(true)) on GeoSearchStoreArgs without also calling count(n); conditionally setting any without setting count on that code path.","commonSituations":"Copy-pasting arg builders between GeoSearchArgs/GeoSearchStoreArgs where count was set elsewhere; a config flag enables ANY but the count option was forgotten; refactor dropped the count call.","solutions":["Always pair any() with count(n), e.g. args.any().count(10)","Remove the any() call if unbounded results are desired","Add a builder-level invariant or test asserting any implies count"],"exampleFix":"// before\nargs.any(); // missing count\n// after\nargs.any().count(10);","handlingStrategy":"validation","validationCode":"if (useAny && count <= 0) {\n    throw new IllegalStateException(\"any() requires a positive count(n)\");\n}\nGeoSearchStoreArgs<V> args = base.anyIf(useAny).count(count);","typeGuard":null,"tryCatchPattern":"try {\n    geoSearchStore(key, dest, args);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"ANY can only be used if COUNT\")) {\n        args.count(DEFAULT_COUNT);\n        geoSearchStore(key, dest, args);\n    } else throw e;\n}","preventionTips":["Make any() and count() set together in a helper method","Add a builder-level or test-level invariant: any implies count","Document the ANY/COUNT dependency where the args are built"],"tags":["redis","argument-validation","geo-commands","option-dependency"],"backgroundTag":"missing-required-option","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"}