Description
Assignment of lazy-initialized members should be the last step with double-checked locking.
now:
public LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> responseData(Map<Uuid, String> topicNames, short version) { if (responseData == null) { synchronized (this) { if (responseData == null) { responseData = 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 -> responseData.put(new TopicPartition(name, partition.partitionIndex()), partition)); } }); } } } return responseData; }
maybe should:
public LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> responseData(Map<Uuid, String> topicNames, short version) { if (responseData == null) { synchronized (this) { if (responseData == null) { // *** change 1 *** 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 -> // *** change 2 *** responseDataTmp.put(new TopicPartition(name, partition.partitionIndex()), partition)); } }); // *** change 3 *** responseData = responseDataTmp; } } } return responseData; }
Attachments
Issue Links
- links to