brandboat commented on code in PR #19803:
URL: https://github.com/apache/kafka/pull/19803#discussion_r2106213940


##########
metadata/src/main/java/org/apache/kafka/metadata/MetadataCache.java:
##########
@@ -148,56 +147,53 @@ DescribeTopicPartitionsResponseData describeTopicResponse(
         boolean ignoreTopicsWithExceptions);
 
     static Cluster toCluster(String clusterId, MetadataImage image) {
-        Map<Integer, List<Node>> brokerToNodes = new HashMap<>();
-        image.cluster().brokers().values().stream()
-            .filter(broker -> !broker.fenced())
-            .forEach(broker -> brokerToNodes.put(broker.id(), broker.nodes()));
+        Map<Integer, Node> nodesById = 
image.cluster().brokers().values().stream()
+            .collect(Collectors.toMap(BrokerRegistration::id, broker -> 
broker.nodes().get(0)));

Review Comment:
   > Fixes a bug where fenced brokers result in NPE.
   
   Like I mentioned in the PR description, this result in a 
NullPointerException.
   Filtering out the fenced broker while PartitionInfo itself still includes 
that fenced broker in replicas can trigger the NPE as we already filter them 
out...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to