-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
Description
Hi, Infer frequently reports false warnings about NULL_DEREFERENCE in common HashMap usage patterns. Below is a minimized code example. At line 7, there is no actual null dereference bug, yet Infer generates a warning as shown in the log below. This appears to be a false positive.
Minimized Code Example
import java.util.*;
class Main {
void check(HashMap<String, String> map) {
for (String key : map.keySet()) {
String s = map.get(key);
if (s.equals("1")) { // report a false warning at this line
// ...
} else {
// ...
}
}
}
public static void main(String[] args) {
Main m = new Main();
HashMap<String, String> map = new HashMap<>();
map.put("1", "2");
m.check(map);
}
}
Log
Main.java:7: error: Null Dereference
`s` could be null (null value originating from line 6) and is dereferenced.
5. for (String key : map.keySet()) {
6. String s = map.get(key);
7. > if (s.equals("1")) {
8. // ...
9. } else {
Infer version: v1.2.0