[Java] False positive for Null Dereference
- Dominant language
- OCaml
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 19h 36m
- Merged PRs (30d)
- 13
Description
In java, Infer sometimes fails to see that null has been accounted for, depending on how nullity is checked for.
## Information
- [x] The version of infer from `infer --version`: 1.1.0
- [x] Your operating system and version: using https://github.com/facebook/infer/blob/main/docker/1.1.0/Dockerfile
- [x] Which command you ran, for example `infer -- make`: `infer run --fail-on-issue -- mvn compile`
- [ ] The full output in a paste, for instance a [gist](https://gist.github.com/).
- [x] If possible, a minimal example to reproduce your problem (for instance, some code where
infer reports incorrectly, together with the way you run infer to reproduce the incorrect
report).
## Logs
```
error: Null Dereference
object `futureResult` last assigned on line 53 could be null and is dereferenced at line 83.
81. } finally {
82. if (Objects.nonNull(futureResult)) {
83. > futureResult.cancel(true);
84. }
85. executor.shutdown();
```
## Example to reproduce
```java
Future variable = null;
if (Objects.nonNull(variable)) {
variable.cancel(); // Infer thinks variable is null here
}
```
This seems to stem from `Objects.nonNull()`: Infer doesn't understand it, and only seem to understand `x != null`.
Contributor guide
Assessment
This issue has not been assessed yet.