{"id":"76cfb7030400a568","repo":"apache/kafka","slug":"invalid-value-null-for-configuration-value-deseria","errorCode":null,"errorMessage":"Invalid value null for configuration value.deserializer: must be non-null.","messagePattern":"Invalid value null for configuration value\\.deserializer: must be non-null\\.","errorType":"exception","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerConfig.java","lineNumber":802,"sourceCode":"            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        }\n    }\n\n    protected void checkUnsupportedConfigsPostProcess() {\n        String groupProtocol = getString(GROUP_PROTOCOL_CONFIG);","sourceCodeStart":784,"sourceCodeEnd":820,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerConfig.java#L784-L820","documentation":"Thrown by ConsumerConfig.appendDeserializerToConfig when neither a value Deserializer instance nor the value.deserializer configuration property is provided. Symmetric to the key.deserializer check; every KafkaConsumer requires a value deserializer to materialize record values. It is a ConfigException raised during KafkaConsumer initialization.","triggerScenarios":"new KafkaConsumer<>(props) (or KafkaConsumer(Map, Deserializer, Deserializer) with valueDeserializer=null) where props does not contain value.deserializer, or where value.deserializer is explicitly null.","commonSituations":"Forgetting value.deserializer when constructing the consumer; passing a non-null key Deserializer but null value Deserializer to the typed constructor; typo in property name (value.deserializer.class); config-loading bug that omits the value deserializer entry.","solutions":["Set props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); before constructing the consumer.","Or pass a non-null value Deserializer instance to the KafkaConsumer(Map, Deserializer, Deserializer) constructor.","Validate config keys at startup to catch typos like value.deserializer.class.","If values are intentionally unused, still provide a ByteArrayDeserializer for the value."],"exampleFix":"// before\nProperties props = new Properties();\nprops.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, \"localhost:9092\");\nprops.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());\nnew KafkaConsumer<>(props); // throws: value.deserializer null\n\n// after\nprops.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());\nnew KafkaConsumer<>(props);","handlingStrategy":"validation","validationCode":"// Ensure value.deserializer is set before constructing the consumer:\nProperties props = new Properties();\nprops.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());\nif (props.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG) == null && valueDeserializer == null) {\n    throw new ConfigException(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, null, \"must be non-null\");\n}","typeGuard":"static boolean hasValueDeserializer(Map<String, Object> configs, Deserializer<?> instance) {\n    return instance != null || configs.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG) != null;\n}","tryCatchPattern":"try {\n    new KafkaConsumer<>(props);\n} catch (ConfigException e) {\n    if (e.getMessage().contains(\"value.deserializer\")) {\n        props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());\n        new KafkaConsumer<>(props);\n    } else throw e;\n}","preventionTips":["Always set value.deserializer explicitly - it is mandatory, there is no useful default.","Pass a Deserializer instance via the KafkaConsumer constructor to guarantee both key and value deserializers are present.","Centralise consumer configuration in one factory so omissions are caught early."],"tags":["consumer","configuration","deserializer","startup","java"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}