Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-2599

Metadata#getClusterForCurrentTopics can throw NPE even with null checking

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 0.8.2.1
    • 0.9.0.0
    • clients
    • None

    Description

      While working on another issue I have just seen the following:

          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);
          }
      

      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.

      Attachments

        Activity

          People

            eribeiro Edward Ribeiro
            eribeiro Edward Ribeiro
            Guozhang Wang Guozhang Wang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: