You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "zhangjk (JIRA)" <ji...@apache.org> on 2018/07/12 10:54:00 UTC
[jira] [Created] (KAFKA-7155) the property CONFIG of the
ProducerConfig maybe null.
zhangjk created KAFKA-7155:
------------------------------
Summary: the property CONFIG of the ProducerConfig maybe null.
Key: KAFKA-7155
URL: https://issues.apache.org/jira/browse/KAFKA-7155
Project: Kafka
Issue Type: Bug
Components: clients
Affects Versions: 1.1.0
Environment: scala 2.12.6
kafka 1.1.0
log4j2 2.11.0
Reporter: zhangjk
hi:
When i use the log4j2's KafkaAppender , I found a bug. the property CONFIG of the ProducerConfig.
here's my code:
{code:java}
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>
{code}
{code:java}
object KafkaTest extends App {
val p = new Producer
}
{code}
{code:java}
class Producer {
val props = {
val p = new Properties()
....
p
}
val producer = {
val p = new KafkaProducer[Integer, String](props)
p
}
}
{code}
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
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)