quarkusio/quarkus · error · IllegalArgumentException
`unit` cannot be `null`
Error message
`unit` cannot be `null`
What it means
byRadius requires a GeoUnit (M, KM, FT, MI) to emit the BYRADIUS <radius> <unit> portion of GEOSEARCH. A null unit would generate a malformed command, so the method throws IllegalArgumentException. Radius value and unit are validated in sequence, radius first.
Source
Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoSearchArgs.java:77
public GeoSearchArgs<V> fromCoordinate(double longitude, double latitude) {
this.longitude = longitude;
this.latitude = latitude;
return this;
}
/**
* Search inside circular area according to given {@code radius}.
*
* @param radius the radius value
* @param unit the unit
* @return the current {@code GeoSearchArgs}
**/
public GeoSearchArgs<V> byRadius(double radius, GeoUnit unit) {
if (radius < 0) {
throw new IllegalArgumentException("`radius` must be positive");
}
if (unit == null) {
throw new IllegalArgumentException("`unit` cannot be `null`");
}
this.radius = radius;
this.unit = unit;
return this;
}
/**
* Search inside circular area according to given {@code radius}.
*
* @param width the width of the box
* @param height the height of the box
* @param unit the unit
* @return the current {@code GeoSearchArgs}
**/
public GeoSearchArgs<V> byBox(double width, double height, GeoUnit unit) {
if (width < 0) {
throw new IllegalArgumentException("`width` must be positive");
}View on GitHub (pinned to e1c734241f)
Solutions
- Pass an explicit GeoUnit constant such as GeoUnit.KM
- Parse unit strings defensively with GeoUnit.valueOf wrapped in a fallback default
- Configure a non-null default unit in application settings
Example fix
// before GeoUnit unit = config.unit(); // may be null args.byRadius(50, unit); // after GeoUnit unit = config.unit() != null ? config.unit() : GeoUnit.KM; args.byRadius(50, unit);
Defensive patterns
Strategy: type-guard
Validate before calling
if (unit == null) { unit = GeoUnit.KM; } Type guard
GeoUnit safeUnit(GeoUnit u) { return u != null ? u : GeoUnit.KM; } Try / catch
try { args.byRadius(radius, unit); } catch (IllegalArgumentException e) { log.error("Unit is null"); } Prevention
- Give config a non-null default unit
- Never let string-to-enum conversions return null silently
- Use Optional<GeoUnit>.orElse default when reading config
When it happens
Trigger: Calling byRadius(radius, null), often when the unit is read from config or mapped from a string that failed to convert to GeoUnit.
Common situations: Config value like quarkus.redis.geo.unit unset and mapped to null; switch/lookup returning null for an unknown unit string; passing another args object's unset unit field.
Related errors
- `member` cannot be `null`
- ANY can only be used if COUNT is also set
- At least `STORE` or `STOREDIST` must be set
- `radius` must be positive
- `width` must be positive
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/6e0bae65ff6f0101.
Report an issue: GitHub.