[ 
https://issues.apache.org/jira/browse/KAFKA-2599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14945732#comment-14945732
 ] 

ASF GitHub Bot commented on KAFKA-2599:
---------------------------------------

Github user asfgit closed the pull request at:

    https://github.com/apache/kafka/pull/262


> Metadata#getClusterForCurrentTopics can throw NPE even with null checking
> -------------------------------------------------------------------------
>
>                 Key: KAFKA-2599
>                 URL: https://issues.apache.org/jira/browse/KAFKA-2599
>             Project: Kafka
>          Issue Type: Bug
>          Components: clients
>    Affects Versions: 0.8.2.1
>            Reporter: Edward Ribeiro
>            Assignee: Edward Ribeiro
>            Priority: Minor
>             Fix For: 0.9.0.0
>
>
> While working on another issue I have just seen the following:
> {code}
>     private Cluster getClusterForCurrentTopics(Cluster cluster) {
>         Collection<PartitionInfo> partitionInfos = new ArrayList<>();
>         if (cluster != null) {
>             for (String topic : this.topics) {
>                 partitionInfos.addAll(cluster.partitionsForTopic(topic));
>             }
>         }
>         return new Cluster(cluster.nodes(), partitionInfos);
>     }
> {code}
> Well, there's a null check for cluster, but if cluster is null it will throw 
> NPE at the return line by calling {{cluster.nodes()}}! So, I put together a 
> quick fix and changed {{MetadataTest}} to reproduce this error.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to