Skip to content

Commit d0708e1

Browse files
Add default get value for task partition map to prevent NPE(#3078)
This PR fixes an NPE in task pipeline caused by a difference in map keyset. In fillActiveTaskCount(..) we iterate over the keyset of one map, but then call .get(key) on a 2nd map. This works on the assumption that the two maps will have the same keyset. The map we get the keys from is built from nodes with task current states and the other is from live and enabled nodes. If there is a node with a current state but has been disabled, then there will be key mismatch and a null value will be returned, which we then attempt to perform arithmetic on (+ operator) and get an NPE. Interestingly, this can only occur after a controller reset as it needs the 2nd map keys to be cleared and repopulated without the disabled node. This fix adds a default get value of 0 to both get operations to prevent any NPEs
1 parent 3d50967 commit d0708e1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

helix-core/src/main/java/org/apache/helix/controller/dataproviders/WorkflowControllerDataProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private void fillActiveTaskCount(Map<String, Integer> additionPartitionMap,
189189
Map<String, Integer> partitionMap) {
190190
for (String participant : additionPartitionMap.keySet()) {
191191
partitionMap.put(participant,
192-
partitionMap.get(participant) + additionPartitionMap.get(participant));
192+
partitionMap.getOrDefault(participant, 0) + additionPartitionMap.getOrDefault(participant, 0));
193193
}
194194
}
195195

0 commit comments

Comments
 (0)