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

the property CONFIG of the ProducerConfig maybe null.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.1.0
    • None
    • clients
    • None
    • scala 2.12.6
      kafka 1.1.0
      log4j2 2.11.0

    Description

      hi:

      When i use the log4j2's KafkaAppender , I found a bug.  the property CONFIG of the ProducerConfig.

      here's my code:

      log4j2.xml
      <Appenders>
          <Kafka name="Kafka" topic="test" key ="KafkaTestKey">
              <PatternLayout pattern="%d{yyyy.MM.dd 'at' HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>
              <Property name="bootstrap.servers">localhost:9092</Property>
          </Kafka>
      </Appenders>
      
      object KafkaTest extends App {
        val p = new Producer
      }
      
      
      class Producer {
        val props = {
          val p = new Properties()
          ....
          p
        }
      
        val producer = {
          val p = new KafkaProducer[Integer, String](props)
          p
        }
      }
      

      The reason for this BUG is that: 

      the `new Producer` is first initialized, and the `ProducerConfig` has a static method block, and it called the `CommonClientConfigs` class. in the `CommonClientConfigs`,  it has a Log property,

      so, this will initialize the Log4j2's configuration, and this will call a startup method of the Appender, and it actually calls the KafkaAppender's method. and then the method create a new `KafkaProducer`, this will create a new `ProducerConfig` instance, but the static method block is not completed, so the `CONFIG` is null.  this cause the `NullPointerException`

       

      my english is bad, so , hope to understand what i mean

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            Garbage_Y zhangjk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: