RivenSun created KAFKA-13793: -------------------------------- Summary: Add validators for serialization and deserialization related configuration Key: KAFKA-13793 URL: https://issues.apache.org/jira/browse/KAFKA-13793 Project: Kafka Issue Type: Improvement Components: clients, config Reporter: RivenSun Assignee: RivenSun
These configurations of producer and consumer have the same problem. {code:java} key.serializer, value.serializer, key.deserializer, value.deserializer{code} Take the `key.serializer` configuration as an example: {code:java} Map<String,Object> props = new HashMap<>(); props.put("key.serializer", null);{code} It is expected that this abnormal configuration can be verified during the startup process of kafkaProducer, but the actual startup result: {code:java} Exception in thread "main" org.apache.kafka.common.KafkaException: Failed to construct kafka producer at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:440) at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:291) at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:274) at us.zoom.mq.server.adapter.kafka.ProducerTest.main(ProducerTest.java:139) Caused by: java.lang.NullPointerException at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:368) ... 3 more {code} There was a line of code that threw a null pointer, causing KafkaProducer initialization to fail. I think we should be able to find this bad configuration during the validation of all the configuration i.e. execute the *ConfigDef.parseValue(ConfigKey key, Object value, boolean isSet) method* and throw a *ConfigException* instead of NullPointerException. Solution: Add *NonNullValidator* to these configurations. For example, when ProducerConfig defines `key.serializer` configuration, add Validator: {code:java} .define(KEY_SERIALIZER_CLASS_CONFIG, Type.CLASS, ConfigDef.NO_DEFAULT_VALUE, new ConfigDef.NonNullValidator(), Importance.HIGH, KEY_SERIALIZER_CLASS_DOC) {code} -- This message was sent by Atlassian Jira (v8.20.1#820001)