uber / uber/NullAway

Not inferring from a first filter in case of two consecutive filters

Open
#353 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
4.1k
Forks
370
Avg merge
1d 13h
Merged PRs (30d)
68

Description

Found this false positive in the code while using.

  class Aclass {

      class Name {
          @Nullable String firstName;
          @Nullable String lastName;
          @Nullable String middleName;
      }

      @Contract("null -> true")
      public boolean isBlank(@Nullable String string) {
          return string == null || string.trim().length() == 0;
      }

      private Observable<Integer> filterThenMap(Observable<Name> observable) {
          return observable
                  .filter(name -> !isBlank(name.firstName) && name.middleName!=null)
                  .filter(name -> name.lastName!=null)
                  .map(name -> name.firstName.length());
      }
  }

This gives warning: [NullAway] dereferenced expression name.firstName is @Nullable at
.map(name -> name.firstName.length());

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 warning with the consecutive-filter example in the issue. Trace how NullAway carries nullness facts from one filter predicate into the next, and consider the issue done when the final map expression is accepted without a false-positive warning.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.