I am retrieving the key and values from the Hashmap using the entrySet(). The code is working fine but the fortify scan is complaining the Null Dereference at map dot entrySet. Below is the code sample. Please suggest.
I tried to put the null checks on the entry.getKey and the entry.getValue().
I tried the null checks on paramMap.entrySet() as well
for (Entry<EnumType, Integer> entry : paramMap.entrySet()) {
if (entry.getKey().name().startsWith("xyz")) {
if (input.charAt(entry.getValue() - 1) == '1') {
list.add(entry.getKey().name().substring(interactionPrefix.length()));
}
}
}
Instead of using the map.entrySet i used the forEach Method which internally take care of the iteration over the key and values.
paramMap.forEach((key, value) ->{
if (key.name().startsWith("xyz")){
if (input.charAt(value - 1) == '1'){ list.add(key.name().substring(interactionPrefix.length()));
}
});