Skip to content

Commit

Permalink
[controller] Return null instead of Collections.emptySet() (#634)
Browse files Browse the repository at this point in the history
In isReplicaDisabled returning emptySet will cause java.lang.UnsupportedOperationException: null exception to be thrown if we try to add any element to it
Instead return null so that it will later create a new HashSet when needed.

---------

Co-authored-by: Sourav Maji <[email protected]>
  • Loading branch information
majisourav99 and Sourav Maji authored Sep 18, 2023
1 parent 90f4631 commit 318183f
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -762,14 +762,12 @@ public boolean isReplicaDisabled(String instance, int partitionId) {
Set<Integer> disabledPartitions = disabledReplicaMap.computeIfAbsent(instance, k -> {
helixClientThrottler.maybeThrottle(1);
Map<String, List<String>> helixMap = helixAdminClient.getDisabledPartitionsMap(clusterName, instance);
if (helixMap.containsKey(kafkaTopic)) {
return helixMap.get(kafkaTopic).stream().map(HelixUtils::getPartitionId).collect(Collectors.toSet());
} else {
return Collections.emptySet();
}
List<String> disablePartitionList = helixMap.get(kafkaTopic);
return disablePartitionList != null
? disablePartitionList.stream().map(HelixUtils::getPartitionId).collect(Collectors.toSet())
: null;
});

return disabledPartitions.contains(partitionId);
return disabledPartitions != null && disabledPartitions.contains(partitionId);
}
};
}
Expand Down

0 comments on commit 318183f

Please sign in to comment.