{"record":{"id":"e2b69adf033822fe","repo":"apache/kafka","slug":"must-be-non-null","errorCode":null,"errorMessage":"must be non-null.","messagePattern":"must be non-null\\.","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerConfig.java","lineNumber":798,"sourceCode":"            String groupInstanceId = this.getString(GROUP_INSTANCE_ID_CONFIG);\n            if (groupInstanceId != null)\n                JoinGroupRequest.validateGroupInstanceId(groupInstanceId);\n\n            String groupInstanceIdPart = groupInstanceId != null ? groupInstanceId : CONSUMER_CLIENT_ID_SEQUENCE.getAndIncrement() + \"\";\n            String generatedClientId = String.format(\"consumer-%s-%s\", groupId, groupInstanceIdPart);\n            configs.put(CLIENT_ID_CONFIG, generatedClientId);\n        }\n    }\n\n    public static Map<String, Object> appendDeserializerToConfig(Map<String, Object> configs,\n                                                                 Deserializer<?> keyDeserializer,\n                                                                 Deserializer<?> valueDeserializer) {\n        // validate deserializer configuration, if the passed deserializer instance is null, the user must explicitly set a valid deserializer configuration value\n        Map<String, Object> newConfigs = new HashMap<>(configs);\n        if (keyDeserializer != null)\n            newConfigs.put(KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializer.getClass());\n        else if (newConfigs.get(KEY_DESERIALIZER_CLASS_CONFIG) == null)\n            throw new ConfigException(KEY_DESERIALIZER_CLASS_CONFIG, null, \"must be non-null.\");\n        if (valueDeserializer != null)\n            newConfigs.put(VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializer.getClass());\n        else if (newConfigs.get(VALUE_DESERIALIZER_CLASS_CONFIG) == null)\n            throw new ConfigException(VALUE_DESERIALIZER_CLASS_CONFIG, null, \"must be non-null.\");\n        return newConfigs;\n    }\n\n    private void maybeOverrideEnableAutoCommit(Map<String, Object> configs) {\n        Optional<String> groupId = Optional.ofNullable(getString(CommonClientConfigs.GROUP_ID_CONFIG));\n        Map<String, Object> originals = originals();\n        boolean enableAutoCommit = originals.containsKey(ENABLE_AUTO_COMMIT_CONFIG) ? getBoolean(ENABLE_AUTO_COMMIT_CONFIG) : false;\n        if (groupId.isEmpty()) { // overwrite in case of default group id where the config is not explicitly provided\n            if (!originals.containsKey(ENABLE_AUTO_COMMIT_CONFIG)) {\n                configs.put(ENABLE_AUTO_COMMIT_CONFIG, false);\n            } else if (enableAutoCommit) {\n                throw new InvalidConfigurationException(ENABLE_AUTO_COMMIT_CONFIG + \" cannot be set to true when default group id (null) is used.\");\n            }\n        }","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerConfig.java#L780-L816","documentation":"Thrown by ConsumerConfig.appendDeserializerToConfig when both the keyDeserializer argument is null AND no value is set for key.deserializer.class in the config map. The consumer requires a way to deserialize keys; it must be supplied either as an instance or a class name. The thrown type is ConfigException.","triggerScenarios":"Calling KafkaConsumer(props, null, valueDeserializer) while props also lacks \"key.deserializer\"; constructing a KafkaConsumer with Properties that omit key.deserializer and passing no key deserializer instance.","commonSituations":"First-time consumer setup forgetting the key.deserializer property; copy-pasting a consumer config template that only had value.deserializer; setting the property to an empty string (treated as not set).","solutions":["Set key.deserializer in your Properties, e.g. props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()).","Or pass a Deserializer instance to the KafkaConsumer constructor for keys.","Use a helper that guarantees both deserializers are configured before constructing the consumer."],"exampleFix":"// before\nProperties props = new Properties();\nprops.put(\"bootstrap.servers\", \"localhost:9092\");\nprops.put(\"value.deserializer\", StringDeserializer.class.getName());\nnew KafkaConsumer<>(props);\n\n// after\nProperties props = new Properties();\nprops.put(\"bootstrap.servers\", \"localhost:9092\");\nprops.put(\"key.deserializer\", StringDeserializer.class.getName());\nprops.put(\"value.deserializer\", StringDeserializer.class.getName());\nnew KafkaConsumer<>(props);","handlingStrategy":"validation","validationCode":"if (keyDeserializer == null && !configs.containsKey(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG)) {\n    throw new ConfigException(\"key.deserializer must be set or a key Deserializer instance provided\");\n}","typeGuard":"static boolean hasKeyDeserializer(Map<String,Object> configs, Deserializer<?> d) {\n    return d != null || configs.containsKey(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG);\n}","tryCatchPattern":"try {\n    consumer = new KafkaConsumer<>(props);\n} catch (ConfigException e) {\n    if (e.getMessage().contains(\"key.deserializer\")) {\n        props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());\n        consumer = new KafkaConsumer<>(props);\n    } else throw e;\n}","preventionTips":["Always set both key.deserializer and value.deserializer in consumer Properties.","Centralize consumer construction so deserializers cannot be forgotten.","Add a config sanity test to your test suite."],"tags":["consumer","config","deserializer","validation"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}