Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-13793

Add validators for serialization and deserialization related configuration

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 3.3.0
    • clients, config
    • None

    Description

      These configurations of producer and consumer have the same problem.

      key.serializer, value.serializer, key.deserializer, value.deserializer

       

      Take the `key.serializer` configuration as an example:

      Map<String,Object> props = new HashMap<>(); 
      props.put("key.serializer", null);

      It is expected that this abnormal configuration can be verified during the startup process of kafkaProducer, but the actual startup result:

      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 

      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:

      .define(KEY_SERIALIZER_CLASS_CONFIG,
              Type.CLASS,
              ConfigDef.NO_DEFAULT_VALUE,
              new ConfigDef.NonNullValidator(),
              Importance.HIGH,
              KEY_SERIALIZER_CLASS_DOC) 

       

      Attachments

        Issue Links

          Activity

            People

              RivenSun RivenSun
              RivenSun RivenSun
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: