Repository navigation
Conversation
Contributor
Author
|
This change is part of the following stack: Change managed by git-spice. |
This was referenced Aug 24, 2026
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1739 +/- ##
============================================
- Coverage 89.44% 89.42% -0.03%
- Complexity 4009 4024 +15
============================================
Files 113 113
Lines 13148 13169 +21
Branches 2723 2734 +11
============================================
+ Hits 11760 11776 +16
Misses 624 624
- Partials 764 769 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
msridhar
force-pushed
the
more-nested-nullness-override-checks
branch
7 times, most recently
from
August 29, 2026 20:48
326ff97 to
4a15623
Compare
msridhar
force-pushed
the
more-nested-nullness-override-checks
branch
2 times, most recently
from
September 9, 2026 21:33
5bdd31d to
39c5b34
Compare
msridhar
force-pushed
the
more-nested-nullness-override-checks
branch
from
September 17, 2026 23:55
39c5b34 to
dfe8279
Compare
msridhar
force-pushed
the
more-nested-nullness-override-checks
branch
from
October 4, 2026 22:54
dfe8279 to
d9b2857
Compare
This was referenced Oct 4, 2026
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 -->
msridhar
pushed a commit
that referenced
this pull request
Oct 21, 2026
…ethods (#2003) An explicitly typed lambda could declare a non-null parameter where the functional interface method, `@NullUnmarked` or otherwise unannotated, has a `@Nullable` parameter that NullAway acknowledges (JSpecify mode, or `AcknowledgeRestrictiveAnnotations=true`), and NullAway reported nothing. An anonymous class, a method reference, and an implicitly typed lambda implementing the same method were reported. `matchLambdaExpression` returned before `checkParamOverriding` whenever the interface method was unannotated, so `RestrictiveAnnotationHandler` never got to mark the parameter. The lambda's parameters are now checked like those of the other implementations. In legacy mode without restrictive annotations no handler marks an unannotated parameter `@Nullable` unless a custom library model does, so default behavior there is unchanged. Sending lambdas through `checkParamOverriding` exposed a varargs defect it already had for anonymous classes and method references. It read the varargs position of `MethodParameterNullness`, which for handler-provided values holds the nullness of the elements; the array's nullness is in `getVarargsArrayNullness()`. Over an unmarked `apply(@nullable Object @nonnull ... inputs)`, an override taking `Object...` was reported, and over `apply(Object @nullable ... inputs)` it was not. The check now uses the array's nullness at the varargs position, both for the overridden method and for a referenced method that receives the whole array, and `RestrictiveAnnotationHandler` now records a type-use `@Nullable` varargs array. `JSpecifyVarargsTests#restrictiveAnnotationsVarargsLambdaUsesArrayNullness` keeps its expectation of no warning: the array is `@NonNull`, and the test now reaches the varargs check it is named for instead of returning early. A library model that sets the varargs array nullness of an overridable method now applies to override checks too, as the handler contract states; no default model does. A method reference whose trailing interface parameters expand into the referenced method's varargs, such as `apply(Object, @nullable Object)` to `take(Object...)`, threw `IndexOutOfBoundsException` from `checkParamOverriding`. The position is now mapped to the varargs parameter and checked by element nullness. Caller sees: - `parameter o is @nonnull, but parameter in functional interface method com.uber.Test.Fi.apply(@nullable Object) is @Nullable` on an explicitly typed lambda over an unmarked or restrictively annotated method. - `parameter inputs of referenced method is @nonnull, but parameter in functional interface method ... is @Nullable` for a method reference against a type-use `@Nullable` varargs array when the referenced varargs array is non-null, including a legacy `@javax.annotation.Nullable Object...`, whose annotation applies to the elements. - No warning for an override or method reference whose varargs elements are `@NonNull` but whose array may be null, where one was reported before. Nested nullness of explicitly typed lambda parameters stays out of scope: #1739 adds that check inside `checkParamOverriding`, which lambdas over unmarked interface methods now reach as well. Also left out, each the same kind of inconsistency found while testing this change: - An expression-bodied lambda over an unannotated method whose return is restrictively `@NonNull` is not checked, while a block-bodied lambda and an anonymous class are. - A plain override or a lambda at the varargs position is still judged by `hasNullableAnnotation`, so an override `apply(@javax.annotation.Nullable Object... p)` of `apply(Object @nullable ... p)` is not reported, while a method reference with the same signature now is. - `CoreNullnessStoreInitializer` gives an implicitly typed lambda parameter at the varargs position the elements' nullness rather than the array's. Fixes #1994 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved nullness analysis for varargs, distinguishing nullable arrays from nullable elements. - Added more accurate checks for varargs overrides, lambdas, and method references, including expanded and unbound references. - Restrictive annotations now correctly recognize both nullable and non-null varargs arrays. - JSpecify analysis now reports mismatches more reliably while accepting compatible nullable assignments. - **Tests** - Added coverage for varargs, lambdas, method references, and restrictive-annotation scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Assisted-by: Codex (gpt-6)
Assisted-by: Codex (gpt-6)
msridhar
force-pushed
the
more-nested-nullness-override-checks
branch
from
November 14, 2026 00:35
d9b2857 to
c01b57f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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