uber / uber/NullAway

False positive with field nullability stored in local variable

Open
#98 21 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.