Skip to content

Check nested nullness for functional interface implementations - #1739

Draft
msridhar wants to merge 2 commits into
masterfrom
more-nested-nullness-override-checks
Draft

msridhar wants to merge 2 commits into
masterfrom
more-nested-nullness-override-checks

Conversation

@msridhar

@msridhar msridhar commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

This closes an important gap in checking, but it causes new errors, and we have other high-priority issues to fix, so going to hold off on landing for a bit

@msridhar

msridhar commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codecov

codecov Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.58209% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.61%. Comparing base (46f47a9) to head (d9b2857).

Files with missing lines Patch % Lines
...ava/com/uber/nullaway/generics/GenericsChecks.java 83.67% 4 Missing and 4 partials ⚠️
...away/src/main/java/com/uber/nullaway/NullAway.java 83.33% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1739      +/-   ##
============================================
- Coverage     87.68%   87.61%   -0.08%     
- Complexity     3524     3536      +12     
============================================
  Files           110      110              
  Lines         11738    11769      +31     
  Branches       2425     2435      +10     
============================================
+ Hits          10293    10311      +18     
- Misses          662      671       +9     
- Partials        783      787       +4     

☔ 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 force-pushed the more-nested-nullness-override-checks branch 7 times, most recently from 326ff97 to 4a15623 Compare August 29, 2026 20:48
@msridhar
msridhar force-pushed the more-nested-nullness-override-checks branch 2 times, most recently from 5bdd31d to 39c5b34 Compare September 9, 2026 21:33
@msridhar
msridhar force-pushed the more-nested-nullness-override-checks branch from 39c5b34 to dfe8279 Compare September 17, 2026 23:55
@msridhar
msridhar force-pushed the more-nested-nullness-override-checks branch from dfe8279 to d9b2857 Compare October 4, 2026 22:54
msridhar added a commit that referenced this pull request Oct 7, 2026
Fixes #1919 

This issue came up while working on #1739. For cases like the test of
#1919, we would sometimes fall back on the `javac`-computed type of an
implicitly-typed lambda parameter. E.g., for this code (from #1919):
```java
  static void implicitParameter(Box<Box<@nullable String>> nested) {
    var flat = nested.flatMap(box -> box);
    acceptsNullable(flat);
  }
```
The type of `box` should be `Box<@nullable String>` based on the
declaration of `nested`, but `javac` computes it as `Box<String>`,
causing a spurious warning.

To fix, store correct types of such parameters in a new map
`lambdaParameterTypesForInference` during inference for the lambda body,
and lookup types in that map as appropriate. We need to carefully update
and restore this map to handle nested lambdas and to not "leak" these
types to other parts of inference (since the types may have references
to unresolved type variables). (The alternative would have been to
thread these types as a parameter through many methods, but that would
have been a more disruptive change.) To handle lambdas like `box -> {
var copy = box; return copy; }`, we also update our visitor to discover
return statements to also discover and register `var`-declared locals.
We disable caching of inferred types whenever
`lambdaParameterTypesForInference` is non-empty to be conservative.

The new tests exercise a number of cases around expression lambdas vs
statement lambdas and nested lambdas.

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

## Summary

* **Bug Fixes**
* Improved nullness inference for implicit lambda parameters in nested
generic calls, local variables, and expression- or block-bodied lambdas.
* Preserved nullable-dereference diagnostics when generic method calls
appear in lambda-local variable initializers, keeping potentially unsafe
dereferences visible.
* Improved recognition of nested nullable types across lambda-body calls
and local assignments, including cases where inferred types are used in
subsequent generic operations.
<!-- 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.

1 participant