{"id":"21c9c0b8fd01df08","repo":"apache/kafka","slug":"value-must-be-non-null","errorCode":null,"errorMessage":"Value must be non-null","messagePattern":"Value must be non-null","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java","lineNumber":1010,"sourceCode":"        /**\n         * A numeric range that checks only the lower bound\n         *\n         * @param min The minimum acceptable value\n         */\n        public static Range atLeast(Number min) {\n            return new Range(min, null);\n        }\n\n        /**\n         * A numeric range that checks both the upper (inclusive) and lower bound\n         */\n        public static Range between(Number min, Number max) {\n            return new Range(min, max);\n        }\n\n        public void ensureValid(String name, Object o) {\n            if (o == null)\n                throw new ConfigException(name, null, \"Value must be non-null\");\n            Number n = (Number) o;\n            if (min != null && n.doubleValue() < min.doubleValue())\n                throw new ConfigException(name, o, \"Value must be at least \" + min);\n            if (max != null && n.doubleValue() > max.doubleValue())\n                throw new ConfigException(name, o, \"Value must be no more than \" + max);\n        }\n\n        public String toString() {\n            if (min == null && max == null)\n                return \"[...]\";\n            else if (min == null)\n                return \"[...,\" + max + \"]\";\n            else if (max == null)\n                return \"[\" + min + \",...]\";\n            else\n                return \"[\" + min + \",...,\" + max + \"]\";\n        }\n    }","sourceCodeStart":992,"sourceCodeEnd":1028,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L992-L1028","documentation":"Thrown by Range.ensureValid when the validated numeric value is null. Range is the built-in Validator used by ConfigDef.Range.atLeast / Range.between, applied to INT/LONG/SHORT/DOUBLE configs to enforce bounds. A null here means the value was not set and there is no default, so the validator refuses it rather than silently treating null as 0.","triggerScenarios":"A config key with a Range validator (e.g. num.network.threads, num.io.threads, request.timeout.ms with bounds, default.api.timeout.ms, fetch.max.bytes, max.partition.fetch.bytes) is omitted from the properties map AND has no default, or is explicitly set to null.","commonSituations":"Custom ConfigDef where a developer added a config with Range.atLeast(1) but forgot to supply a default; programmatic property assembly that puts null for missing keys; Spring @ConfigurationProperties binding a missing Optional as null and forwarding it; partial config objects merged where a key is later overwritten with null.","solutions":["Provide an explicit non-null value for the property.","Or define a sensible default in the ConfigDef entry (ConfigDef.Definition].defaultValue(…)).","Filter out null entries before building the properties map (e.g. props.values().removeIf(Objects::isNull)).","If the validator should permit null, use a different/combined Validator (e.g. a null-safe wrapper) or make the config optional at the schema level."],"exampleFix":"// before\nprops.put(ConsumerConfig.FETCH_MIN_BYTES_CONFIG, null);\n// -> ConfigException: Value must be non-null\n\n// after\nprops.put(ConsumerConfig.FETCH_MIN_BYTES_CONFIG, 1);\n// or omit it so the documented default applies","handlingStrategy":"validation","validationCode":"if (value == null) {\n    throw new IllegalArgumentException(\"config '\" + key + \"' must be a non-null number\");\n}","typeGuard":"public static boolean isNonNullNumber(Object v) {\n    return v instanceof Number;\n}","tryCatchPattern":"try {\n    configDef.parse(configs);\n} catch (ConfigException e) {\n    if (e.getMessage().equals(\"Value must be non-null\")) {\n        // supply the documented default and retry\n    } else throw e;\n}","preventionTips":["Never leave a ranged numeric config unset unless you have verified it has a default.","Treat null as an explicit, invalid input at the config-loading boundary."],"tags":["config","validation","null-value","client"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}