False Negative: NULL_DEREFERENCE missing when a field is explicitly assigned null in the constructor
- Dominant language
- OCaml
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 19h 36m
- Merged PRs (30d)
- 13
Description
**Description**
Infer fails to report a NULL_DEREFERENCE (or NULLPTR_DEREFERENCE) when a class field is explicitly initialized to null within the constructor and subsequently dereferenced in another instance method.
**To Reproduce**
``` Java
class Test {
String x;
// Case 1
public Test() {
this.x = null;
}
public void testExplicitField() {
x.trim(); //<-should report (FN)
}
// Case 2
public void testLocalDereference() {
String y = null;
y.length(); // <-reported (TP)
}
}
```
**Expected behavior**
Infer should report a NULL_DEREFERENCE for the line x.trim(); in testExplicitField(). The analysis should be able to propagate the null state from the constructor to the method call for the same instance.
**Actual behavior**
Infer only reports the issue in Case2. The dereference of the field x in Case1 is silently ignored, even though it was explicitly assigned null in the class's own constructor.
Contributor guide
Assessment
This issue has not been assessed yet.