NullPointerException in KafkaConsumer with group.instance.id
`log` in KafkaConsumer does not get initialized if an invalid value for group.intance.id is given during consumer construction. In this case we should skip the catch block's close procedure since no internal objects have been initialized yet.
Reviewers: Guozhang Wang
@@ -568,7 +568,7 @@ public class KafkaConsumer<K, V> implements Consumer<K, V> {
final Metrics metrics;
final KafkaConsumerMetrics kafkaConsumerMetrics;
- private final Logger log;
+ private Logger log;
private final String clientId;
private String groupId;
private final ConsumerCoordinator coordinator;
@@ -815,7 +815,10 @@ public class KafkaConsumer<K, V> implements Consumer<K, V> {
log.debug("Kafka consumer initialized");
} catch (Throwable t) {
// call close methods if internal objects are already constructed; this is to prevent resource leak. see KAFKA-2121
+ // we do not need to call `close` at all when `log` is null, which means no internal objects were initialized.
+ if (this.log != null) {
close(0, true);
+ }
// now propagate the exception
throw new KafkaException("Failed to construct kafka consumer", t);
}
