{"record":{"id":"c4956b3f370a19de","repo":"quarkusio/quarkus","slug":"unit-cannot-be-null-c4956b","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/GeoSearchStoreArgs.java","lineNumber":71,"sourceCode":"    private GeoSearchStoreArgs<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 GeoSearchStoreArgs}\n     **/\n    public GeoSearchStoreArgs<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 GeoSearchStoreArgs}\n     **/\n    public GeoSearchStoreArgs<V> byBox(double width, double height, GeoUnit unit) {\n        if (width < 0) {\n            throw new IllegalArgumentException(\"`width` must be positive\");\n        }","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoSearchStoreArgs.java#L53-L89","documentation":"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.","triggerScenarios":"Calling byRadius(radius, null) — typically a null field, a missing enum mapping, or a variable assigned from a lookup that returned null.","commonSituations":"Unit read from config not mapped to GeoUnit; switch/default path leaving unit null; refactor from String to GeoUnit without defaulting.","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"],"exampleFix":"// before\nGeoUnit unit = unitMap.get(configUnit); // may be null\nargs.byRadius(10, unit);\n// after\nGeoUnit unit = unitMap.getOrDefault(configUnit, GeoUnit.km);\nargs.byRadius(10, unit);","handlingStrategy":"validation","validationCode":"if (unit == null) {\n    throw new IllegalArgumentException(\"unit must not be null\");\n}\nargs.byRadius(radius, unit);","typeGuard":"boolean isValidUnit(GeoUnit unit) { return unit != null; }","tryCatchPattern":"try {\n    args.byRadius(radius, unit);\n} catch (IllegalArgumentException e) {\n    log.error(\"Null GeoUnit: {}\", e.getMessage());\n    args.byRadius(radius, GeoUnit.km);\n}","preventionTips":["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"],"tags":["redis","null-argument","argument-validation","geo-commands"],"backgroundTag":"null-argument","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}