[ https://issues.apache.org/jira/browse/KAFKA-12841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17372984#comment-17372984 ]
Kirk True commented on KAFKA-12841: ----------------------------------- There are some conditions inside the {{KafkaProducer}}'s {{doSend}} method that will result in an {{ApiException}} being thrown before the {{TopicPartition}} ({{tp}}) is created. As a result, {{tp}} is null and case #2 listed in the initial bug report occurs. Would it be OK to create a new, "dummy" {{TopicPartition}} in this case? We could use the topic from the {{ProducerRecord}}. But perhaps the partition from the {{ProducerRecord}}, if non-null, can be used? Or should we just set the partition to `-1`? > NPE from the provided metadata in client callback in case of ApiException > ------------------------------------------------------------------------- > > Key: KAFKA-12841 > URL: https://issues.apache.org/jira/browse/KAFKA-12841 > Project: Kafka > Issue Type: Bug > Components: clients > Affects Versions: 2.6.0 > Environment: Prod > Reporter: Avi Youkhananov > Priority: Major > Attachments: NPE.production > > > 1. > org.apache.kafka.clients.producer.Callback interface has method > onCompletion(...) > Which says as part of the documentation : > *The metadata for the record that was sent (i.e. the partition and offset). > *An empty metadata with -1 value for all fields* except for topicPartition > will be returned if an error occurred. > We got an NPE from doSend(...) method in > org.apache.kafka.clients.producer.KafkaProducer > Which can occur in case ApiException was thrown ... > In case of ApiException it uses the regular callback instead of > InterceptorCallback which also may cover the NPE. > 2. More over RecordMetadata has method partition() which return int but can > also throw NPE because TopicPartition might be null. > Stack trace attached. > -- This message was sent by Atlassian Jira (v8.3.4#803005)