typetools / typetools/checker-framework
False negative: Nullness Checker allows leaking implicit `@UnderInitialization this` to inner class c'tor
Open
@smillst is already working on this.
Since Dec 3, 2020.
False Negative (missing warning or unsoundness)
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Nullness Checker apparently does not verify the implicit reference to enclosing class instance.
Let's consider the following class:
class SampleClass {
final InnerClass inner;
final String foo;
SampleClass() {
this.inner = new InnerClass();
this.inner.bar(); /// WHOOPS... NPE
this.foo = "Hello world";
}
class InnerClass {
String bar() {
return foo.substring(1);
}
}
}
This compiles with no error, despite clearly leading to an NPE in the runtime.
A nearly equivalent snippet that uses a static nested class instead:
class SampleClass {
final InnerClass inner;
final String foo;
SampleClass() {
this.inner = new InnerClass(this); // Ok, NullnessChecker raises an error
this.inner.bar();
this.foo = "Hello world";
}
static class InnerClass {
SampleClass outer;
InnerClass(SampleClass outer) {
this.outer = outer;
}
String bar() {
return outer.foo.substring(1);
}
}
}
fails as expected on nullness:assignment.type.incompatible and argument.type.incompatible.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.