uber / uber/NullAway

Support field nullability information in stream closures for final fields

Open
#604 5 comments 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

NullAway throws an error [NullAway] dereferenced expression allowedNames is @Nullable at .filter(name -> allowedNames.contains(name)). I was not expecting this error because of the explicit null check for allowedNames.

import java.util.stream.Collectors;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;

 class TestStream{

    @Nullable private final Set<String> allowedNames;
    TestStream(@Nullable Set<String> allowedNames) {
      this.allowedNames = allowedNames;
    }

    private List<String> filterAllowedNames(List<String> inputNames){
      if (allowedNames == null) {
        return inputNames;
      }
      if (allowedNames.isEmpty()) {
        return Collections.emptyList();
      }
      return inputNames
              .stream()
              .filter(name -> allowedNames.contains(name))
              .collect(Collectors.toList());

    }
  }

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

The issue provides a Java TestStream reproducer in the report; start by running it through NullAway and confirming the false-positive dereference warning inside the stream filter closure. Trace how the analyzer carries nullability for the final allowedNames field into closures. Done means the explicit null check is respected and the reproducer no longer reports an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
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.