Fix bug with lambdas assigned to locals with a wildcard in their type - #1647
Conversation
|
This change is part of the following stack:
Change managed by git-spice. |
73e9097 to
48b2fe9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1647 +/- ##
=========================================
Coverage 88.16% 88.17%
+ Complexity 3066 3064 -2
=========================================
Files 105 105
Lines 10303 10301 -2
Branches 2080 2079 -1
=========================================
- Hits 9084 9083 -1
Misses 576 576
+ Partials 643 642 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f056a9a to
0156e31
Compare
48b2fe9 to
6a0dab6
Compare
0156e31 to
bd65c72
Compare
6a0dab6 to
afa1d09
Compare
bd65c72 to
69e379d
Compare
afa1d09 to
c0a7b38
Compare
69e379d to
62af508
Compare
c0a7b38 to
974105a
Compare
Walkthrough
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 |
I don't think I can parse this... Edit: never mind, s/were/here/g, right? I thought there was something more complicated going on |
lazaroclapp
left a comment
There was a problem hiding this comment.
This seems correct, given the tests and just the general notion that we still have to perform "deep" nullness inference on locals, surprised the fix was this straightforward without any side effects 😁
62af508 to
0b639da
Compare
974105a to
ccd037a
Compare
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/test/java/com/uber/nullaway/jspecify/GenericsTests.java (1)
2010-2010: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winRemove
@Nullablefrom this local variable.Repository guidance forbids annotating local variables with
@Nullable; NullAway infers local nullability automatically. UseObject[] o = ...instead.As per coding guidelines and retrieved learnings, local nullability annotations should not be added in this codebase.
🤖 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/test/java/com/uber/nullaway/jspecify/GenericsTests.java` at line 2010, Remove the `@Nullable` annotation from the local variable declaration in GenericsTests, changing it to an unannotated Object[] while preserving the existing conditional assignment and inferred nullability behavior.Sources: Coding guidelines, Learnings
🤖 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/test/java/com/uber/nullaway/jspecify/GenericsTests.java`:
- Line 2010: Remove the `@Nullable` annotation from the local variable declaration
in GenericsTests, changing it to an unannotated Object[] while preserving the
existing conditional assignment and inferred nullability behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 44fb0a68-e00e-49b7-8ba4-692e4de74673
📒 Files selected for processing (3)
nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.javanullaway/src/test/java/com/uber/nullaway/jspecify/GenericLambdaTests.javanullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java
0b639da to
224af39
Compare
ccd037a to
7aaa8e3
Compare
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/test/java/com/uber/nullaway/jspecify/GenericsTests.java (1)
2010-2010: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winAnnotate the array reference, not its elements.
@Nullable Object[]permits nullable elements but keeps the array reference non-null. Since the conditional expression can evaluate tonull, this test should useObject@nullable[] o; otherwisedoTest()should report a nullability error.Based on learnings,
@Nullable Object[]andObject@nullable[]have different nullability targets.🤖 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/test/java/com/uber/nullaway/jspecify/GenericsTests.java` at line 2010, Update the declaration of o in the GenericsTests test so `@Nullable` annotates the array reference using the Object `@Nullable` [] syntax, not the element type. Preserve the conditional assignment and ensure doTest() reports no nullability error for the nullable array reference.Source: Learnings
🤖 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/test/java/com/uber/nullaway/jspecify/GenericsTests.java`:
- Line 2010: Update the declaration of o in the GenericsTests test so `@Nullable`
annotates the array reference using the Object `@Nullable` [] syntax, not the
element type. Preserve the conditional assignment and ensure doTest() reports no
nullability error for the nullable array reference.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 9032e39d-8f5c-42ee-a7f6-33f98eda6d9d
📒 Files selected for processing (3)
nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.javanullaway/src/test/java/com/uber/nullaway/jspecify/GenericLambdaTests.javanullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java
This PR enables the JSpecify JDK models for all regression tests run in JSpecify mode. The change exposed a bug where enabling the JDK models also enabled loading of external astubx files. We fix that here and only load external astubx files if JarInfer is enabled. There were a couple of issues exposed by this change by our current tests. One is documented in #1616. Another is fixed in #1647, a follow-up to this PR. Another is just a change in the warning that gets printed. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a new compiler option to enable JSpecify JDK model support (`-XepOpt:NullAway:JSpecifyJDKModels=true`). * **Bug Fixes** * Improved how JSpecify-related compiler arguments are composed and processed when JSpecify mode is enabled. * Updated stubx model caching to only load stubx files when JarInfer-based model loading is enabled. * **Tests** * Adjusted JSpecify JDK models test configurations and updated expected nullability/diagnostic outcomes for generics, conditional expressions, and stream filtering. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Lázaro Clapp <lazaro@uber.com>
7aaa8e3 to
1c4dc6d
Compare
Yes, sorry for the typo! |
Previously, we only used the target type of an assignment when inferring the type of a lambda / method reference when a field was being assigned. But this is incorrect; we should also use declared types of local variables. (I think I was confused about local inference before; the top-level nullability of locals does get inferred, but here we need the type arguments, which are not inferred).
Summary by CodeRabbit
Bug Fixes
extendswildcard nullness (including nullable bounds) is reflected more accurately in diagnostics.Tests
Supplier<? extends@nullableObject>target and verifying expected nullness behavior.@Nullable” diagnostic that no longer applies in that snippet.