quarkusio/quarkus · error · IllegalArgumentException
ANY can only be used if COUNT is also set
Error message
ANY can only be used if COUNT is also set
What it means
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.
Source
Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoSearchArgs.java:190
/**
* When ANY is provided the command will return as soon as enough matches are found, so the results may not be the
* ones closest to the specified point, but on the other hand, the effort invested by the server is significantly
* lower.
* <p>
* Using {@code ANY} requires {@code count} to be set.
*
* @return the current {@code GeoRadiusArgs}
**/
public GeoSearchArgs<V> any() {
this.any = true;
return this;
}
@Override
public List<Object> toArgs(Codec codec) {
// Validation
if (any && count == -1) {
throw new IllegalArgumentException("ANY can only be used if COUNT is also set");
}
if (radius > 0 && width > 0) {
throw new IllegalArgumentException("BYRADIUS and BYBOX cannot be used together");
}
if (member != null && (latitude != Double.MIN_VALUE || longitude != Double.MIN_VALUE)) {
throw new IllegalArgumentException("FROMMEMBER and FROMLONLAT cannot be used together");
}
List<Object> list = new ArrayList<>();
if (member != null) {
list.add("FROMMEMBER");
list.add(new String(codec.encode(member), StandardCharsets.UTF_8));
} else {
list.add("FROMLONLAT");
list.add(Double.toString(longitude));
list.add(Double.toString(latitude));View on GitHub (pinned to e1c734241f)
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
Example fix
// before
GeoSearchArgs<String> args = GeoSearchArgs.fromMember("palermo")
.byRadius(200, GeoUnit.KM)
.any();
// after
GeoSearchArgs<String> args = GeoSearchArgs.fromMember("palermo")
.byRadius(200, GeoUnit.KM)
.count(20)
.any(); Defensive patterns
Strategy: validation
Validate before calling
if (args.isAny() && args.getCount() == -1) { throw new IllegalStateException("ANY requires COUNT"); } Try / catch
try { geo.geoSearch(key, args); } catch (IllegalArgumentException e) { log.error("Invalid geo args: " + e.getMessage()); } Prevention
- Always call count(n) when using any()
- Build args in a single helper that enforces the rule
- Cover args combinations with unit tests
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- ANY can only be used if COUNT is also set
- `radius` must be positive
- `width` must be positive
- `height` must be positive
- At least `STORE` or `STOREDIST` must be set
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/ca10a558573234ac.
Report an issue: GitHub.