This is an automated email from the ASF dual-hosted git repository. schofielaj pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push: new 2ce7c446124 KAFKA-19198: Resolve NPE when topic assigned in share group is deleted (#19552) 2ce7c446124 is described below commit 2ce7c4461247ea720e6aec36b3c549d7016b3c7e Author: Andrew Schofield <aschofi...@confluent.io> AuthorDate: Fri Apr 25 08:44:56 2025 +0100 KAFKA-19198: Resolve NPE when topic assigned in share group is deleted (#19552) This PR just resolves an NPE when a topic assigned in a share group is deleted. The NPE is caused by code which uses the current metadata image to convert from a topic ID to the topic name. For a deleted topic, there is no longer any entry in the image. A future PR will properly handle the topic deletion. Reviewers: Apoorv Mittal <apoorvmitta...@gmail.com>, PoAn Yang <pay...@apache.org> --- .../kafka/coordinator/group/GroupMetadataManager.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java b/group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java index f73e24549f8..7336c2fb775 100644 --- a/group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java +++ b/group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java @@ -4963,9 +4963,13 @@ public class GroupMetadataManager { private Map<Uuid, String> attachTopicName(Set<Uuid> topicIds) { TopicsImage topicsImage = metadataImage.topics(); - return topicIds.stream() - .map(topicId -> Map.entry(topicId, topicsImage.getTopic(topicId).name())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + Map<Uuid, String> finalMap = new HashMap<>(); + for (Uuid topicId : topicIds) { + TopicImage topicImage = topicsImage.getTopic(topicId); + String topicName = (topicImage != null) ? topicImage.name() : "<UNKNOWN>"; + finalMap.put(topicId, topicName); + } + return Collections.unmodifiableMap(finalMap); } private Map<Uuid, Map.Entry<String, Set<Integer>>> attachTopicName(Map<Uuid, Set<Integer>> initMap) { @@ -4973,7 +4977,8 @@ public class GroupMetadataManager { Map<Uuid, Map.Entry<String, Set<Integer>>> finalMap = new HashMap<>(); for (Map.Entry<Uuid, Set<Integer>> entry : initMap.entrySet()) { Uuid topicId = entry.getKey(); - String topicName = topicsImage.getTopic(topicId).name(); + TopicImage topicImage = topicsImage.getTopic(topicId); + String topicName = (topicImage != null) ? topicImage.name() : "<UNKNOWN>"; finalMap.put(topicId, Map.entry(topicName, entry.getValue())); } return Collections.unmodifiableMap(finalMap);