False positive with field nullability stored in local variable
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Java
- Stars
- 4.1k
- Forks
- 370
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 68
Description
In this case, a @Nullable field is stored to a local variable. When the field is used in a null condition an error occurs, but if the variable is used then it does not. It seems the data flow analysis does not realize they are the same.
error: [NullAway] returning @Nullable expression from method with @NonNull return type
return (writer == null) ? CacheWriter.disabledWriter() : castedWriter;
^
<K1 extends K, V1 extends V> CacheWriter<K1, V1> getCacheWriter() {
@SuppressWarnings("unchecked")
CacheWriter<K1, V1> castedWriter = (CacheWriter<K1, V1>) writer;
return (writer == null) ? CacheWriter.disabledWriter() : castedWriter;
}
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.
Research direction
Start by reproducing the Java example and tracing the nullability data-flow handling for the @Nullable writer field and its castedWriter local variable. Done means the analysis recognizes the field and local as equivalent in the shown condition and no longer reports the false positive; add or update a regression test for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100