Details
-
Bug
-
Status: Open
-
Critical
-
Resolution: Unresolved
-
2.11.0
-
None
-
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 is null.
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>
the main class:
object KafkaTest extends App { // this is scala code. // create a KafkaProducer val p = new Producer }
producer code:
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` class, it has a static Log property, so, this will initialize the Log4j2's configuration, and this will call a startup method of the Appender, 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