chia7712 commented on code in PR #15966: URL: https://github.com/apache/kafka/pull/15966#discussion_r1605998588
########## clients/src/main/java/org/apache/kafka/common/requests/FetchResponse.java: ########## @@ -99,28 +99,24 @@ public Errors error() { } public LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> responseData(Map<Uuid, String> topicNames, short version) { - if (responseData == null) { - synchronized (this) { - if (responseData == null) { - // Assigning the lazy-initialized `responseData` in the last step - // to avoid other threads accessing a half-initialized object. - final LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> responseDataTmp = - new LinkedHashMap<>(); - data.responses().forEach(topicResponse -> { - String name; - if (version < 13) { - name = topicResponse.topic(); - } else { - name = topicNames.get(topicResponse.topicId()); - } - if (name != null) { - topicResponse.partitions().forEach(partition -> - responseDataTmp.put(new TopicPartition(name, partition.partitionIndex()), partition)); - } - }); - responseData = responseDataTmp; + synchronized (this) { + // Assigning the lazy-initialized `responseData` in the last step + // to avoid other threads accessing a half-initialized object. + final LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> responseDataTmp = + new LinkedHashMap<>(); + data.responses().forEach(topicResponse -> { + String name; + if (version < 13) { + name = topicResponse.topic(); + } else { + name = topicNames.get(topicResponse.topicId()); } - } + if (name != null) { + topicResponse.partitions().forEach(partition -> + responseDataTmp.put(new TopicPartition(name, partition.partitionIndex()), partition)); + } + }); + responseData = responseDataTmp; Review Comment: This is what I do concern! The `responseData` could be different if the input gets changed. -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org