{"record":{"id":"b86cc025ce237b0b","repo":"redis/jedis","slug":"count-must-be-set-before-any-to-be-set","errorCode":null,"errorMessage":"COUNT must be set before ANY to be set","messagePattern":"COUNT must be set before ANY to be set","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/params/GeoRadiusParam.java","lineNumber":65,"sourceCode":"  public GeoRadiusParam sortingOrder(SortingOrder order) {\n    this.sortingOrder = order;\n    return this;\n  }\n\n  public GeoRadiusParam count(int count) {\n    this.count = count;\n    return this;\n  }\n\n  public GeoRadiusParam count(int count, boolean any) {\n    this.count = count;\n    this.any = any;\n    return this;\n  }\n\n  public GeoRadiusParam any() {\n    if (this.count == null) {\n      throw new IllegalArgumentException(\"COUNT must be set before ANY to be set\");\n    }\n    this.any = true;\n    return this;\n  }\n\n  @Override\n  public void addParams(CommandArguments args) {\n\n    if (withCoord) {\n      args.add(Keyword.WITHCOORD);\n    }\n    if (withDist) {\n      args.add(Keyword.WITHDIST);\n    }\n    if (withHash) {\n      args.add(Keyword.WITHHASH);\n    }\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/params/GeoRadiusParam.java#L47-L83","documentation":"In GEOSEARCH/GEOSEARCHSTORE (and GEORADIUS variants), the ANY modifier is only meaningful together with COUNT: it lets Redis return the first matching members found rather than the nearest ones. GeoRadiusParam.any() enforces ordering — if count was never set, calling any() throws IllegalArgumentException telling the caller to set COUNT first.","triggerScenarios":"Calling geoRadiusParam().any() (or geoSearchParam...any()) without a preceding count(n) on the same params object; building params where any() is invoked before count() in the builder chain.","commonSituations":"Copying GEOSEARCH ANY examples from the Redis CLI without the accompanying COUNT; method-chaining any() first out of reading order; generic param builders that apply flags in the wrong sequence.","solutions":["Call count(n) before any(): geoRadiusParam().count(10).any().","If unlimited results are wanted, remove any() — it has no meaning without COUNT.","Wrap params construction in a helper that always applies count first when any is requested."],"exampleFix":"// before\nGeoRadiusParam params = GeoRadiusParam.geoRadiusParam().any(); // COUNT missing\n// after\nGeoRadiusParam params = GeoRadiusParam.geoRadiusParam().count(10).any();","handlingStrategy":"validation","validationCode":"if (wantAny && countValue == null) {\n  throw new IllegalArgumentException(\"GEO any() requires count(n) first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  jedis.geosearch(key, member, radius, unit, params);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"COUNT must be set before ANY\")) {\n    params = GeoRadiusParam.geoRadiusParam().count(defaultCount).any();\n  } else throw e;\n}","preventionTips":["Always write the builder chain as count(n).any(), never any() alone.","Omit any() entirely when you do not need early termination semantics.","Centralize geo params construction in one helper to keep flag ordering correct."],"tags":["params","georadius","geo","argument-order"],"backgroundTag":"invalid-argument-value","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}