{"record":{"id":"8468411a76bf5a51","repo":"redis/jedis","slug":"both-byradius-and-bybox-cannot-be-used","errorCode":null,"errorMessage":"Both BYRADIUS and BYBOX cannot be used.","messagePattern":"Both BYRADIUS and BYBOX cannot be used\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/params/GeoSearchParam.java","lineNumber":129,"sourceCode":"    }\n    this.any = true;\n    return this;\n  }\n\n  @Override\n  public void addParams(CommandArguments args) {\n    if (fromMember && fromLonLat) {\n      throw new IllegalArgumentException(\"Both FROMMEMBER and FROMLONLAT cannot be used.\");\n    } else if (fromMember) {\n      args.add(Keyword.FROMMEMBER).add(member);\n    } else if (fromLonLat) {\n      args.add(Keyword.FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude());\n    } else {\n      throw new IllegalArgumentException(\"Either FROMMEMBER or FROMLONLAT must be used.\");\n    }\n\n    if (byRadius && byBox) {\n      throw new IllegalArgumentException(\"Both BYRADIUS and BYBOX cannot be used.\");\n    } else if (byRadius) {\n      args.add(Keyword.BYRADIUS).add(radius).add(unit);\n    } else if (byBox) {\n      args.add(Keyword.BYBOX).add(width).add(height).add(unit);\n    } else {\n      throw new IllegalArgumentException(\"Either BYRADIUS or BYBOX must be used.\");\n    }\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":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/params/GeoSearchParam.java#L111-L147","documentation":"GEOSEARCH accepts exactly one search shape: BYRADIUS or BYBOX. GeoSearchParam.addParams() detects both being set and throws this IllegalArgumentException because the resulting command would be ambiguous and rejected by Redis.","triggerScenarios":"Calling both .byRadius(...) and .byBox(...) (or .byBox with both width/height variants) on the same GeoSearchParam before execution.","commonSituations":"Code paths that switch between radius and box searches but both run on a shared params object; default params pre-populated with byRadius then updated with byBox instead of being rebuilt.","solutions":["Remove one of the two shape calls so only byRadius OR byBox remains","Rebuild a fresh GeoSearchParam when switching search shape instead of mutating a shared instance","Branch explicitly: use byRadius for radius semantics, byBox for rectangle semantics"],"exampleFix":"// before\nGeoSearchParam p = new GeoSearchParam().fromMember(\"sicily\").byRadius(100, GeoUnit.KM).byBox(100, 100, GeoUnit.KM);\n// after\nGeoSearchParam p = new GeoSearchParam().fromMember(\"sicily\").byBox(100, 100, GeoUnit.KM);","handlingStrategy":"type-guard","validationCode":"if (useRadius && useBox) throw new IllegalStateException(\"Choose BYRADIUS or BYBOX, not both\");","typeGuard":"GeoSearchParam shape(GeoSearchParam p, boolean byRadius, double r, double w, double h, GeoUnit u) {\n  return byRadius ? p.byRadius(r, u) : p.byBox(w, h, u);\n}","tryCatchPattern":"try {\n  jedis.geosearch(key, params);\n} catch (IllegalArgumentException e) {\n  params = new GeoSearchParam().fromMember(m).byRadius(r, unit);\n}","preventionTips":["Pick the search shape from a single enum/flag, not two booleans","Rebuild params when switching shape","Never apply byBox to a params object already carrying byRadius"],"tags":["jedis","geosearch","mutually-exclusive","illegal-argument"],"backgroundTag":"mutually-exclusive-options","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"}