You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Edward Ribeiro (JIRA)" <ji...@apache.org> on 2015/09/29 23:15:05 UTC
[jira] [Updated] (KAFKA-2599) Metadata#getClusterForCurrentTopics
can throw NPE even with null checking
[ https://issues.apache.org/jira/browse/KAFKA-2599?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Edward Ribeiro updated KAFKA-2599:
----------------------------------
Description:
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.
was:
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. So, I put together a quick fix and changed {{MetadataTest}} to reproduce this error.
> 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.8.1.2, 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)