NullAway icon indicating copy to clipboard operation
NullAway copied to clipboard

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

Open shubhamugare opened this issue 6 years ago • 1 comments

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());

shubhamugare avatar Sep 09 '19 05:09 shubhamugare

Yeah I think our Rx support is a bit brittle and needs one-off support for cases like this. We can think about how to make it more robust.

msridhar avatar Sep 16 '19 17:09 msridhar