Repository navigation
Fix handling of reference to method with @Nullable parameter from library model - #1642
Conversation
|
This change is part of the following stack:
Change managed by git-spice. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1642 +/- ##
============================================
+ Coverage 88.17% 88.20% +0.03%
- Complexity 3058 3060 +2
============================================
Files 105 105
Lines 10271 10282 +11
Branches 2073 2074 +1
============================================
+ Hits 9056 9069 +13
+ Misses 573 572 -1
+ Partials 642 641 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
WalkthroughMethod-reference override checking now propagates handler-provided nullness for the referenced method and gives it precedence when determining overriding parameter nullness. The library model marks Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
nullaway/src/main/java/com/uber/nullaway/NullAway.java (1)
994-1014: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winMap index to varargs parameter index before querying handler overrides.
The newly added logic queries
referencedMethodParameterNullnessOverridesusingmethodParamInd. However, if the method reference targets a varargs method and the varargs are passed individually,methodParamIndcan exceed the formal parameters' indices. Handlers likeLibraryModelsHandlerstore the varargs element nullness at the index of the varargs array parameter (i.e.varargsIndex).By passing the unmapped
methodParamInd,getParameterNullnesswill returnnullfor indices beyond the varargs array parameter, causing the handler-provided nullness override for varargs elements to be incorrectly ignored.Move the
getMemberRefParamIndexcomputation to the top of the method and use it to bound the index before querying the override.🐛 Proposed fix
private boolean paramOfOverridingMethodIsNonNull( VarSymbol paramSymbol, int methodParamInd, Symbol.@Nullable MethodSymbol overridingMethod, boolean isMethodAnnotated, `@Nullable` MemberReferenceTree memberReferenceTree, Type.@Nullable MethodType memberReferenceMethodType, `@Nullable` MethodParameterNullness referencedMethodParameterNullnessOverrides) { + int memberRefParamIndex = + getMemberRefParamIndex(methodParamInd, overridingMethod, memberReferenceTree); if (referencedMethodParameterNullnessOverrides != null) { Nullness parameterNullnessOverride = - referencedMethodParameterNullnessOverrides.getParameterNullness(methodParamInd); + referencedMethodParameterNullnessOverrides.getParameterNullness(memberRefParamIndex); if (parameterNullnessOverride != null) { // An explicit handler value takes precedence over annotations and generic substitution. return parameterNullnessOverride.equals(Nullness.NONNULL); } } boolean result = false; if (isMethodAnnotated) { result = !Nullness.hasNullableAnnotation(paramSymbol, config); } else if (config.acknowledgeRestrictiveAnnotations()) { // can still be `@NonNull` if there is a restrictive annotation result = Nullness.hasNonNullAnnotation(paramSymbol, config); } if (result && memberReferenceMethodType != null) { // when the overriding method is a member reference, also check that the parameter is not // effectively `@Nullable` due to generics. memberReferenceMethodType should be the method type // of the member reference after handling generics com.sun.tools.javac.util.List<Type> parameterTypes = memberReferenceMethodType.getParameterTypes(); - int memberRefParamIndex = - getMemberRefParamIndex(methodParamInd, overridingMethod, memberReferenceTree); Type paramType = parameterTypes.get(memberRefParamIndex);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@nullaway/src/main/java/com/uber/nullaway/NullAway.java` around lines 994 - 1014, Move the getMemberRefParamIndex computation to the beginning of paramOfOverridingMethodIsNonNull, then query referencedMethodParameterNullnessOverrides.getParameterNullness using the mapped index. Ensure varargs method-reference arguments beyond the formal varargs parameter use the varargs array index, while preserving the existing annotation and generic-substitution logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@nullaway/src/main/java/com/uber/nullaway/NullAway.java`:
- Around line 994-1014: Move the getMemberRefParamIndex computation to the
beginning of paramOfOverridingMethodIsNonNull, then query
referencedMethodParameterNullnessOverrides.getParameterNullness using the mapped
index. Ensure varargs method-reference arguments beyond the formal varargs
parameter use the varargs array index, while preserving the existing annotation
and generic-substitution logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 54256134-7590-466b-8314-beb79dc3e145
📒 Files selected for processing (3)
nullaway/src/main/java/com/uber/nullaway/NullAway.javatest-library-models/src/main/java/com/uber/nullaway/testlibrarymodels/TestLibraryModels.javatest-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java
|
The integration test failure is due to the new checking here. I put up a fix: spring-projects/spring-boot#51091 |
439fe21 to
d220b1a
Compare
a1a802f to
0f1d1b0
Compare
Consider the following case:
Say that the parameter of
UnannotatedWithModels::isNonNullis not declared with a@Nullableannotation, but should be treated as@Nullabledue to a library model. In such a case, before we would still report a warning for the above code thatUnannotatedWithModels::isNonNullcannot take a@Nullableparameter, since we weren't checking the library models in the right place. This PR corrects this issue. This fix will be relevant to uses ofObjects::isNonNullin stream pipelines when we enable JDK library models.Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
Tests
Stream.filter(...)when using method references (validated viaanyMatch(...)).