{"id":"a2968d76003701ac","repo":"apache/kafka","slug":"entry-must-be-non-null","errorCode":null,"errorMessage":"entry must be non null","messagePattern":"entry 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":1158,"sourceCode":"        @Override\n        public void ensureValid(String name, Object o) {\n            String s = (String) o;\n            if (s == null || !validStrings.contains(s.toUpperCase(Locale.ROOT))) {\n                throw new ConfigException(name, o, \"String must be one of (case insensitive): \" + String.join(\", \", validStrings));\n            }\n        }\n\n        public String toString() {\n            return \"(case insensitive) [\" + String.join(\", \", validStrings) + \"]\";\n        }\n    }\n\n    public static class NonNullValidator implements Validator {\n        @Override\n        public void ensureValid(String name, Object value) {\n            if (value == null) {\n                // Pass in the string null to avoid the spotbugs warning\n                throw new ConfigException(name, \"null\", \"entry must be non null\");\n            }\n        }\n\n        public String toString() {\n            return \"non-null string\";\n        }\n    }\n\n    public static class LambdaValidator implements Validator {\n        BiConsumer<String, Object> ensureValid;\n        Supplier<String> toStringFunction;\n\n        private LambdaValidator(BiConsumer<String, Object> ensureValid,\n                                Supplier<String> toStringFunction) {\n            this.ensureValid = ensureValid;\n            this.toStringFunction = toStringFunction;\n        }\n","sourceCodeStart":1140,"sourceCodeEnd":1176,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L1140-L1176","documentation":"Thrown by NonNullValidator.ensureValid when the validated value is null. NonNullValidator is the simplest Validator implementation: it permits any non-null value (no type or content checks) and rejects only null. The literal string \"null\" is passed as the value argument to ConfigException to satisfy spotbugs/nullable-analysis, so the exception's getValue() reports \"null\" rather than a null reference.","triggerScenarios":"A ConfigKey registered with .validator(new NonNullValidator()) (or equivalent) is parsed and the properties Map has no entry for that key and the ConfigKey has no default, or the key is explicitly mapped to null. Triggered during ConfigDef.parse() within the validator loop.","commonSituations":"Required identifier configs (client.id, transactional.id, group.instance.id, or module-specific required strings) left unset in properties files. Common when a config was previously optional with a default and a version bump made a default absent, or when env-var templating fails to substitute.","solutions":["Set the named config to any non-null value in your Properties/Map.","If the config is genuinely optional, give the ConfigKey a sensible default via ConfigDef.define(..., defaultValue, ...).","Audit env-var/secret-injection pipelines (e.g. Kubernetes secretKeyRef) to confirm the source actually produced a value."],"exampleFix":"// before\n// client.id omitted entirely\nprops.put(\"bootstrap.servers\", \"localhost:9092\");\n\n// after\nprops.put(\"bootstrap.servers\", \"localhost:9092\");\nprops.put(\"client.id\", \"order-service-producer\");","handlingStrategy":"type-guard","validationCode":"// Reject null at the boundary for keys known to use NonNullValidator (e.g. client.id, transactional.id):\nfor (String nonNullKey : Set.of(\"client.id\", \"transactional.id\")) {\n    if (configs.containsKey(nonNullKey) && configs.get(nonNullKey) == null) {\n        throw new IllegalArgumentException(nonNullKey + \" must not be null\");\n    }\n}","typeGuard":"// Use Java's Optional or @NonNull annotation to make null impossible in your config wrapper:\nrecord KafkaConfig(@NonNull String clientId, @NonNull String bootstrapServers) {}\n// then map fields -> Properties, never exposing null.","tryCatchPattern":"try {\n    new KafkaProducer<>(props);\n} catch (ConfigException ce) {\n    if (ce.getMessage().contains(\"entry must be non null\")) {\n        log.error(\"Required kafka config '{}' was null\", ce.getName());\n        failStartup();\n    } else throw ce;\n}","preventionTips":["Use a typed config record/class with non-null fields so nulls can't enter the Properties map.","Enable static analysis (Spotbugs NP_NULL_PARAM) on the call site that builds Properties.","Avoid configs.put(key, System.getenv(VAR)) without a null guard — env vars are frequently unset."],"tags":["config","kafka-client","validation","validator","null"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}