Source:
<code>public void onPartitionMerge(AvailabilityStrategyContext context, Collection<CacheStatusResponse> statusResponses) { CacheTopology maxStableTopology = null; for (CacheStatusResponse response : statusResponses) { CacheTopology stableTopology = response.getStableTopology(); if (stableTopology == null) { continue; } if (maxStableTopology == null || maxStableTopology.getMembers().size() < stableTopology.getMembers().size()) { maxStableTopology = stableTopology; } } CacheTopology maxTopology = null; for (CacheStatusResponse response : statusResponses) { CacheTopology stableTopology = response.getStableTopology(); if (!Objects.equals(stableTopology, maxStableTopology)) continue; CacheTopology topology = response.getCacheTopology(); if (topology == null) { continue; } if (maxTopology == null || maxTopology.getMembers().size() < topology.getMembers().size()) { maxTopology = topology; } } if (maxTopology == null) { log.debugf("No current topology, recovered only joiners for cache %s", context.getCacheName()); } int maxTopologyId = 0; for (CacheStatusResponse response : statusResponses) { CacheTopology topology = response.getCacheTopology(); if (topology != null && maxTopologyId < topology.getTopologyId()) { maxTopologyId = topology.getTopologyId(); } } CacheTopology mergedTopology = maxTopology; <START> if (maxTopology != null) { <END> mergedTopology = new CacheTopology(maxTopologyId + 1, maxTopology.getRebalanceId(), maxTopology.getCurrentCH(), null, maxTopology.getActualMembers()); } context.updateTopologiesAfterMerge(mergedTopology, maxStableTopology, null); List<Address> newMembers = context.getExpectedMembers(); List<Address> survivingMembers = new ArrayList<>(mergedTopology.getMembers()); if (survivingMembers.retainAll(newMembers)) { checkForLostData(context, survivingMembers); } context.updateCurrentTopology(survivingMembers); context.queueRebalance(newMembers); }</code><technical_language>related PR: understand this piece of code. in line before, setting mergedTopology = maxTopology if (maxTopology != null) setting a new CacheTopology. is pointing set mergedTopology = maxTopology? BTW, IDEA is telling line 132 produce NPE</technical_language>

Target:
public void onPartitionMerge(AvailabilityStrategyContext context, Collection<CacheStatusResponse> statusResponses) { CacheTopology maxStableTopology = null; for (CacheStatusResponse response : statusResponses) { CacheTopology stableTopology = response.getStableTopology(); if (stableTopology == null) { continue; } if (maxStableTopology == null || maxStableTopology.getMembers().size() < stableTopology.getMembers().size()) { maxStableTopology = stableTopology; } } CacheTopology maxTopology = null; for (CacheStatusResponse response : statusResponses) { CacheTopology stableTopology = response.getStableTopology(); if (!Objects.equals(stableTopology, maxStableTopology)) continue; CacheTopology topology = response.getCacheTopology(); if (topology == null) { continue; } if (maxTopology == null || maxTopology.getMembers().size() < topology.getMembers().size()) { maxTopology = topology; } } if (maxTopology == null) { log.debugf("No current topology, recovered only joiners for cache %s", context.getCacheName()); } int maxTopologyId = 0; for (CacheStatusResponse response : statusResponses) { CacheTopology topology = response.getCacheTopology(); if (topology != null && maxTopologyId < topology.getTopologyId()) { maxTopologyId = topology.getTopologyId(); } } CacheTopology mergedTopology = null; if (maxTopology != null) { mergedTopology = new CacheTopology(maxTopologyId + 1, maxTopology.getRebalanceId(), maxTopology.getCurrentCH(), null, maxTopology.getActualMembers()); } context.updateTopologiesAfterMerge(mergedTopology, maxStableTopology, null); List<Address> newMembers = context.getExpectedMembers(); List<Address> survivingMembers = new ArrayList<>(newMembers); if (mergedTopology != null && survivingMembers.retainAll(mergedTopology.getMembers())) { checkForLostData(context, survivingMembers); } context.updateCurrentTopology(survivingMembers); context.queueRebalance(newMembers); }