Infer incorrectly reports NULL_DEREFERENCE for HashMap operations
- Dominant language
- OCaml
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 19h 36m
- Merged PRs (30d)
- 13
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
```java
import java.util.*;
class Main {
void check(HashMap 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 map = new HashMap<>();
map.put("1", "2");
m.check(map);
}
}
```
### Log
```bash
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
Contributor guide
Assessment
This issue has not been assessed yet.