quarkusio/quarkus · error · IllegalArgumentException
`unit` cannot be `null`
Error message
`unit` cannot be `null`
What it means
GeoSearchStoreArgs.byRadius(radius, unit) requires a non-null GeoUnit because the unit is serialized as the BYRADIUS unit token (m/km/ft/mi). A null unit would yield an invalid Redis command, so the library throws IllegalArgumentException.
Source
Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoSearchStoreArgs.java:71
private GeoSearchStoreArgs<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 GeoSearchStoreArgs}
**/
public GeoSearchStoreArgs<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 GeoSearchStoreArgs}
**/
public GeoSearchStoreArgs<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 (GeoUnit.m, GeoUnit.km, GeoUnit.ft, GeoUnit.mi)
- Default the unit when the lookup fails, e.g. Optional.ofNullable(lookup(u)).orElse(GeoUnit.km)
- Validate/configure the unit mapping before building the args
Example fix
// before GeoUnit unit = unitMap.get(configUnit); // may be null args.byRadius(10, unit); // after GeoUnit unit = unitMap.getOrDefault(configUnit, GeoUnit.km); args.byRadius(10, unit);
Defensive patterns
Strategy: validation
Validate before calling
if (unit == null) {
throw new IllegalArgumentException("unit must not be null");
}
args.byRadius(radius, unit); Type guard
boolean isValidUnit(GeoUnit unit) { return unit != null; } Try / catch
try {
args.byRadius(radius, unit);
} catch (IllegalArgumentException e) {
log.error("Null GeoUnit: {}", e.getMessage());
args.byRadius(radius, GeoUnit.km);
} Prevention
- Map config unit strings to GeoUnit with an explicit default
- Avoid returning null from unit parsers; use Optional or throw
- Enumerate GeoUnit values in tests for config mapping
When it happens
Trigger: Calling byRadius(radius, null) — typically a null field, a missing enum mapping, or a variable assigned from a lookup that returned null.
Common situations: Unit read from config not mapped to GeoUnit; switch/default path leaving unit null; refactor from String to GeoUnit without defaulting.
Related errors
- `member` cannot be `null`
- `overflowType` must not be `null`
- FROMMEMBER and FROMLONLAT cannot be used together
- `radius` must be positive
- `width` must be positive
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/c4956b3f370a19de.
Report an issue: GitHub.