typetools / typetools/checker-framework
@EnsuresNonNull[If] should ensure all fields on a path are non-null
@wmdietl is already working on this.
Since Mar 27, 2018.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
In the example below, method bar ensures that this.field.value is non-null.
However an error for the dereference of this.field is generated.
I looked at the Store and it only contains a value for this.field.value, not for this.field, which explains the error.
Probably similar problems exist for other flow expressions.
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
class Demo {
class A {
@Nullable Object value;
}
@Nullable A field;
@EnsuresNonNull("this.field.value")
void bar() {
this.field = new A();
this.field.value = "";
}
void foo() {
bar();
this.field.toString();
}
}
I'm working on an improvement to the CFG & Store and noticed this issue when debugging an issue at
https://github.com/typetools/checker-framework/blob/master/checker/src/org/checkerframework/checker/initialization/InitializationVisitor.java#L183
I don't understand why that code doesn't fail on master, but this false positive illustrates the same issue with the Store.
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.