facebook / facebook/infer

False Positive in Infer Null Pointer Dereference Detection

Open
#1,931 0 comments 0 reactions 1 assignee Claimed by @Gabisampaio View on GitHub
false-positive java
Dominant language
OCaml
Stars
15.7k
Forks
2.1k
Avg merge
19h 36m
Merged PRs (30d)
13

Description

Hi, I used Infer to detect null pointer dereference issues and encountered a false positive. Below is a minimized example where Infer reports an NPD warning at ​​line 6​​, even though this line is unreachable.

This appears to be a false positive. Let me know if you need further details.

### Code Example
```java
public class Main {
public static void foo() {
List l = Collections.emptyList();
if (!l.isEmpty()) {
Object o = null;
o.toString(); // report a false NPD warning here
}
}

public static void main(String[] args) {
foo();
}
}
```

### Log
```bash
Found 1 source file to analyze in /path/to/infer-out
4/4 [##########################################################################] 100% 175ms

Main.java:137: error: Null Dereference
`o` could be null (null value originating from line 136) and is dereferenced.
135. if (!l.isEmpty()) {
136. Object o = null;
137. > o.toString();
138. }
139. }
```
### Version
Infer version v1.2.0 MacOS

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.