Skip to content

Fix crash in map callbacks after an unmarked or suppressed filter predicate - #1996

Merged
msridhar merged 3 commits into
uber:masterfrom
vlsi:fix-1990-filter-unmarked
Oct 21, 2026
Merged

msridhar merged 3 commits into
uber:masterfrom
vlsi:fix-1990-filter-unmarked

Conversation

@vlsi

@vlsi vlsi commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

When the filter predicate of a java.util.stream or RxJava chain was an anonymous class whose test method is @NullUnmarked or @SuppressWarnings("NullAway"), NullAway crashed while checking the map callback after it, and compilation failed with:

java.lang.IllegalStateException: null filterNullStore for tree

StreamNullabilityPropagator records the facts that hold when a filter predicate returns true, and records them only for a predicate NullAway checks. A predicate in unmarked or suppressed code leaves no record, and neither does a checked predicate whose every return is the literal false. Both readers of the record, the initial store of a map lambda or anonymous method and an unbound method reference passed to map, threw on the missing record.

They now add no facts in that case, so the callback is checked as if no filter preceded it. A callback after an always-false predicate never runs, so a dereference in it may be reported; adding no facts is the conservative choice and is the same as for an unchecked predicate.

Caller sees: dereferenced expression '<expr>' is @Nullable or referenced method returns @Nullable where a map callback relies on a null check in such a predicate, instead of the crash.

Tests cover Stream and RxJava, both annotations, the method reference path, and an always-false lambda predicate, each next to a checked-predicate control that keeps its facts; the non-control tests fail on master with the exception above.

Fixes #1990

Assisted-by: Claude Code (claude-opus-5-5)

Summary by CodeRabbit

  • Bug Fixes

    • Prevented crashes when processing Stream and RxJava filters with unavailable nullability information.
    • Avoided propagating nullability facts from unmarked, suppressed, or never-true predicates.
    • Preserved nullability propagation for checked predicates that can return true.
  • Tests

    • Added regression coverage for Stream and RxJava filter/map scenarios, including method references.

vlsi added 2 commits October 20, 2026 19:12
These tests fail with IllegalStateException: null filterNullStore for tree.

Assisted-by: Claude Code (claude-opus-5-5)
…dicate

When the `filter` predicate of a java.util.stream or RxJava chain was an anonymous class whose `test` method is `@NullUnmarked` or `@SuppressWarnings("NullAway")`, NullAway crashed while checking the `map` callback after it, and compilation failed with:

    java.lang.IllegalStateException: null filterNullStore for tree

StreamNullabilityPropagator records the facts that hold when a filter predicate returns true, and records them only for a predicate NullAway checks. A predicate in unmarked or suppressed code leaves no record, and neither does a checked predicate whose every return is the literal `false`. Both readers of the record, the initial store of a `map` lambda or anonymous method and an unbound method reference passed to `map`, threw on the missing record.

They now add no facts in that case, so the callback is checked as if no filter preceded it. A callback after an always-false predicate never runs, so a dereference in it may be reported; adding no facts is the conservative choice and is the same as for an unchecked predicate.

Caller sees: `dereferenced expression '<expr>' is @Nullable` or `referenced method returns @Nullable` where a `map` callback relies on a null check in such a predicate, instead of the crash.

Tests cover Stream and RxJava, both annotations, the method reference path, and an always-false lambda predicate, each next to a checked-predicate control that keeps its facts; the non-control tests fail on master with the exception above.

Fixes uber#1990

Assisted-by: Claude Code (claude-opus-5-5)
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: uber/NullAway/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 0905acb3-94f0-4f3c-b803-7de4b870ec24
📥 Commits

Reviewing files that changed from the base of the PR and between 10c1bdf and 42a0cdc.

📒 Files selected for processing: 2
  • nullaway/src/main/java/com/uber/nullaway/handlers/StreamNullabilityPropagator.java
  • nullaway/src/test/java/com/uber/nullaway/FrameworkTests.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

StreamNullabilityPropagator now returns without adding facts when a filter nullness store is unavailable. This applies to method-reference handling and dataflow initialization. Regression tests cover Stream and RxJava callbacks after unchecked, suppressed, always-false, and checked predicates.

Suggested reviewers: msridhar

Priority: ➖ Normal

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 42a0c

The change can proceed through normal checks; no actionable merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description clearly explains the crash, the affected Stream and RxJava paths, the intended behavior, and the regression tests.
Title check Passed The title clearly and concisely identifies the crash fix for map callbacks after unmarked or suppressed filter predicates.
Linked Issues check Passed Issue [#1990] requires NullAway to stop crashing after unchecked @NullUnmarked or @SuppressWarnings("NullAway") filter predicates for Java Stream and RxJava chains. StreamNullabilityPropagator n…
Out of Scope Changes check Passed The production change is limited to missing filter-store handling in StreamNullabilityPropagator. The added test helpers and cases verify the linked Stream and RxJava behavior, including the conserv…
Full details: Linked Issues check

Explanation

Issue [#1990] requires NullAway to stop crashing after unchecked @NullUnmarked or @SuppressWarnings("NullAway") filter predicates for Java Stream and RxJava chains. StreamNullabilityPropagator now returns without adding facts when filterToNSMap has no entry, both for map callback initial stores and unbound method references. The tests cover Stream and RxJava, both annotations, method references, always-false predicates, and checked predicates that retain facts. The reproducer callback continues without the exception, and the nullable test callbacks receive nullable diagnostics instead of a plugin crash.

Full details: Out of Scope Changes check

Explanation

The production change is limited to missing filter-store handling in StreamNullabilityPropagator. The added test helpers and cases verify the linked Stream and RxJava behavior, including the conservative no-facts behavior for always-false predicates. These changes support issue [#1990] and show no unrelated functionality.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.10%. Comparing base (83d4466) to head (42a0cdc).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1996      +/-   ##
============================================
+ Coverage     88.05%   88.10%   +0.04%     
  Complexity       38       38              
============================================
  Files           117      117              
  Lines         11941    11940       -1     
  Branches       2444     2444              
============================================
+ Hits          10515    10520       +5     
+ Misses          647      644       -3     
+ Partials        779      776       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@msridhar
msridhar enabled auto-merge (squash) October 21, 2026 00:45
@msridhar
msridhar merged commit f7b81c4 into uber:master Oct 21, 2026
30 of 31 checks passed
msridhar pushed a commit that referenced this pull request Oct 21, 2026
…literals (#2002)

Parentheses around a lambda, a method reference, a stream receiver, or a boolean literal produced false positives, because several handlers matched those trees with `instanceof` on the tree as written, and a `ParenthesizedTree` matched none of their cases. For example, `s.filter((b -> b.get() != null)).map(b -> b.get().length())` reported `dereferenced expression 'b.get()' is @Nullable`, and an `@EnsuresNonNullIf("item")` method that ends in `return (false);` after `if (item != null) { return (true); }` reported `Method is annotated with @EnsuresNonNullIf but does not ensure fields [item]`. The same code without the parentheses compiles cleanly.

The handlers now strip parentheses before they match, at these sites:

- `StreamNullabilityPropagator`: the argument of `filter` and `map` (lambda, method reference, or anonymous class); the receiver that links a stream call to the call before it, as in `(s.filter(...)).map(...)`; the argument of `collect` and the lambdas passed to the collector factory; the boolean literal a filter returns; and, in JSpecify mode, the method reference that marks a filter as null-rejecting, as in `filter((Objects::nonNull))`.
- `EnsuresNonNullIfHandler`: the boolean literal a return statement returns.
- `SynchronousCallbackHandler`: a parenthesized lambda passed to a method whose callbacks run synchronously, such as `Iterable.forEach`, gets the access paths of the enclosing method, as an unparenthesized one does.

The other `instanceof` checks in the handlers either receive expressions through `NullAway.mayBeNullExpr`, which already strips parentheses and casts, or test dataflow nodes, which carry no parentheses.

Caller sees:
- `java.lang.IllegalStateException: null filterNullStore for tree` when a stream filter can only return `(false)`, as plain `return false;` already does on master; #1996 removes that exception for both forms.
- No `dereferenced expression ... is @Nullable`, `incompatible types`, or `Method is annotated with @EnsuresNonNullIf but does not ensure fields` warning for the parenthesized forms above.

Each new test fails on master with the false positive and passes with this change; each fixed site has its own test, and controls with the same parentheses but no null check still report.

Part of #1993 (groups B and C). Casts (group A) are #1997 and the parenthesized arguments to unmarked code in `GenericsChecks` (group D) are #1999. #1996 also edits `StreamNullabilityPropagator`, in `onDataflowInitialStore` and `onMatchMethodReference`, which this change does not touch.

Assisted-by: Claude Code (claude-opus-5-5)


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Bug Fixes**
  * Improved nullability analysis for expressions enclosed in parentheses.
  * Stream, reactive, callback, and `forEach` expressions now correctly preserve nullness information when parenthesized.
  * Parenthesized boolean literals are now validated correctly in nullability contracts.
  * Collector handling, chained calls, method references, and lambda expressions now recognize equivalent parenthesized forms.

* **Tests**
  * Added coverage for parenthesized Stream, RxJava, callback, lambda, collector, and contract expressions.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IllegalStateException "null filterNullStore for tree" when a stream filter predicate is @NullUnmarked or suppressed

2 participants