Fix wildcard inference bug with method references#1553
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1553 +/- ##
=========================================
Coverage 88.45% 88.45%
Complexity 2869 2869
=========================================
Files 103 103
Lines 9586 9587 +1
Branches 1930 1930
=========================================
+ Hits 8479 8480 +1
Misses 532 532
Partials 575 575 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
8a2f2aa to
2ebfce6
Compare
2fe233b to
ed48bd5
Compare
ea94de5 to
2f392ee
Compare
ed48bd5 to
6ec1a79
Compare
2f392ee to
adb858c
Compare
6ec1a79 to
fc48e50
Compare
|
This change is part of the following stack: Change managed by git-spice. |
| list.stream().map(Test::mapToNull).forEach(s -> { | ||
| if (s != null) { s.hashCode(); } | ||
| }); | ||
| list.stream().map(Test::mapToNull).forEach(Test::doNothing); |
There was a problem hiding this comment.
Probably also worth checking that, without the map to null, a Stream<String> works just fine with .forEach(Test::callHashCode);, no?
fc48e50 to
b3118a6
Compare
f027fde to
f379612
Compare
WalkthroughThe PR modifies Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.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/generics/GenericsChecks.java (1)
1601-1622:⚠️ Potential issue | 🟠 Major | ⚡ Quick winStore the target-derived poly type before relation checks.
At Line 1621,
maybeStorePolyExpressionTypeFromTarget(...)runs afterprocessMethodRefTypeRelations(...)and this branch then returns. That ordering can miss target-annotated type info during the relation check itself.Suggested fix
if (currentActualParam instanceof MemberReferenceTree memberReferenceTree) { + maybeStorePolyExpressionTypeFromTarget(currentActualParam, formalParameter); // the type of the method reference tree provided by javac may not capture // nullability of nested types. So, do explicit type checks based on the return and // parameter types of the referenced method GenericsUtils.processMethodRefTypeRelations( this, @@ reportInvalidMethodReferenceParameterTypeError( memberReferenceTree, subtype, supertype, state); } } }); - maybeStorePolyExpressionTypeFromTarget(currentActualParam, formalParameter); return; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java` around lines 1601 - 1622, The poly-expression target-derived type is being stored too late: call maybeStorePolyExpressionTypeFromTarget(currentActualParam, formalParameter) before invoking GenericsUtils.processMethodRefTypeRelations(...) so that the relation checks (inside processMethodRefTypeRelations involving reportInvalidMethodReferenceReturnTypeError and reportInvalidMethodReferenceParameterTypeError) see any target-provided annotations; move the maybeStorePolyExpressionTypeFromTarget call to immediately prior to the processMethodRefTypeRelations(...) invocation in the branch handling currentActualParam instanceof MemberReferenceTree.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java`:
- Around line 1601-1622: The poly-expression target-derived type is being stored
too late: call maybeStorePolyExpressionTypeFromTarget(currentActualParam,
formalParameter) before invoking
GenericsUtils.processMethodRefTypeRelations(...) so that the relation checks
(inside processMethodRefTypeRelations involving
reportInvalidMethodReferenceReturnTypeError and
reportInvalidMethodReferenceParameterTypeError) see any target-provided
annotations; move the maybeStorePolyExpressionTypeFromTarget call to immediately
prior to the processMethodRefTypeRelations(...) invocation in the branch
handling currentActualParam instanceof MemberReferenceTree.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2b83059c-dcbe-4ccc-a131-2ea10ae66901
📒 Files selected for processing (2)
nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.javanullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java
Fixes #1552
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests