{"record":{"id":"6e0bae65ff6f0101","repo":"quarkusio/quarkus","slug":"unit-cannot-be-null","errorCode":null,"errorMessage":"`unit` cannot be `null`","messagePattern":"`unit` cannot be `null`","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoSearchArgs.java","lineNumber":77,"sourceCode":"    public GeoSearchArgs<V> fromCoordinate(double longitude, double latitude) {\n        this.longitude = longitude;\n        this.latitude = latitude;\n        return this;\n    }\n\n    /**\n     * Search inside circular area according to given {@code radius}.\n     *\n     * @param radius the radius value\n     * @param unit the unit\n     * @return the current {@code GeoSearchArgs}\n     **/\n    public GeoSearchArgs<V> byRadius(double radius, GeoUnit unit) {\n        if (radius < 0) {\n            throw new IllegalArgumentException(\"`radius` must be positive\");\n        }\n        if (unit == null) {\n            throw new IllegalArgumentException(\"`unit` cannot be `null`\");\n        }\n        this.radius = radius;\n        this.unit = unit;\n        return this;\n    }\n\n    /**\n     * Search inside circular area according to given {@code radius}.\n     *\n     * @param width the width of the box\n     * @param height the height of the box\n     * @param unit the unit\n     * @return the current {@code GeoSearchArgs}\n     **/\n    public GeoSearchArgs<V> byBox(double width, double height, GeoUnit unit) {\n        if (width < 0) {\n            throw new IllegalArgumentException(\"`width` must be positive\");\n        }","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoSearchArgs.java#L59-L95","documentation":"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.","triggerScenarios":"Calling byRadius(radius, null), often when the unit is read from config or mapped from a string that failed to convert to GeoUnit.","commonSituations":"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.","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"],"exampleFix":"// before\nGeoUnit unit = config.unit(); // may be null\nargs.byRadius(50, unit);\n// after\nGeoUnit unit = config.unit() != null ? config.unit() : GeoUnit.KM;\nargs.byRadius(50, unit);","handlingStrategy":"type-guard","validationCode":"if (unit == null) { unit = GeoUnit.KM; }","typeGuard":"GeoUnit safeUnit(GeoUnit u) { return u != null ? u : GeoUnit.KM; }","tryCatchPattern":"try { args.byRadius(radius, unit); } catch (IllegalArgumentException e) { log.error(\"Unit is null\"); }","preventionTips":["Give config a non-null default unit","Never let string-to-enum conversions return null silently","Use Optional<GeoUnit>.orElse default when reading config"],"tags":["redis","geo","null-check","illegal-argument"],"backgroundTag":"null-argument","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}