Follow-on fix for restoring annotation on captured type wildcards - #1667
Follow-on fix for restoring annotation on captured type wildcards#1667msridhar wants to merge 3 commits into
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
Walkthrough
Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java`:
- Around line 435-472: Add Javadoc to the non-trivial test method
wildcardCaptureRestoresConcreteAnnotatedBound, briefly documenting the
wildcard-capture regression scenario it covers and the expected diagnostic
behavior. Leave the test implementation and assertions unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: c2d25661-5a50-4c3e-8453-7e0b17e9ee3f
📒 Files selected for processing (3)
nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.javanullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.javatest-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java
| @Test | ||
| public void wildcardCaptureRestoresConcreteAnnotatedBound() { | ||
| makeHelper() | ||
| .addSourceLines( | ||
| "Test.java", | ||
| """ | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
| @NullMarked | ||
| class Test { | ||
| static class Nested<T extends @Nullable Object> { | ||
| Nested<T> self() { | ||
| return this; | ||
| } | ||
| Nested<? extends @Nullable T> wildcardUpperTypeVariable() { | ||
| throw new RuntimeException(); | ||
| } | ||
| } | ||
|
|
||
| Nested<? extends String> testDirect(Nested<? extends String> receiver) { | ||
| // BUG: Diagnostic contains: incompatible types | ||
| return receiver.wildcardUpperTypeVariable(); | ||
| } | ||
|
|
||
| Nested<? extends String> testWithSelf(Nested<? extends String> receiver) { | ||
| // BUG: Diagnostic contains: incompatible types | ||
| return receiver.self().wildcardUpperTypeVariable(); | ||
| } | ||
|
|
||
| Nested<? extends String> testWithVar(Nested<? extends String> receiver) { | ||
| var local = receiver; | ||
| // BUG: Diagnostic contains: incompatible types | ||
| return local.wildcardUpperTypeVariable(); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add Javadoc for this non-trivial regression test.
Proposed fix
`@Test`
+ /** Verifies nullable bounds are restored for captured extends wildcards across receiver paths. */
public void wildcardCaptureRestoresConcreteAnnotatedBound() {As per coding guidelines, “Add Javadoc to every non-trivial method, including private methods.”
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| @Test | |
| public void wildcardCaptureRestoresConcreteAnnotatedBound() { | |
| makeHelper() | |
| .addSourceLines( | |
| "Test.java", | |
| """ | |
| import org.jspecify.annotations.NullMarked; | |
| import org.jspecify.annotations.Nullable; | |
| @NullMarked | |
| class Test { | |
| static class Nested<T extends @Nullable Object> { | |
| Nested<T> self() { | |
| return this; | |
| } | |
| Nested<? extends @Nullable T> wildcardUpperTypeVariable() { | |
| throw new RuntimeException(); | |
| } | |
| } | |
| Nested<? extends String> testDirect(Nested<? extends String> receiver) { | |
| // BUG: Diagnostic contains: incompatible types | |
| return receiver.wildcardUpperTypeVariable(); | |
| } | |
| Nested<? extends String> testWithSelf(Nested<? extends String> receiver) { | |
| // BUG: Diagnostic contains: incompatible types | |
| return receiver.self().wildcardUpperTypeVariable(); | |
| } | |
| Nested<? extends String> testWithVar(Nested<? extends String> receiver) { | |
| var local = receiver; | |
| // BUG: Diagnostic contains: incompatible types | |
| return local.wildcardUpperTypeVariable(); | |
| } | |
| } | |
| """) | |
| .doTest(); | |
| } | |
| `@Test` | |
| /** Verifies nullable bounds are restored for captured extends wildcards across receiver paths. */ | |
| public void wildcardCaptureRestoresConcreteAnnotatedBound() { | |
| makeHelper() | |
| .addSourceLines( | |
| "Test.java", | |
| """ | |
| import org.jspecify.annotations.NullMarked; | |
| import org.jspecify.annotations.Nullable; | |
| `@NullMarked` | |
| class Test { | |
| static class Nested<T extends `@Nullable` Object> { | |
| Nested<T> self() { | |
| return this; | |
| } | |
| Nested<? extends `@Nullable` T> wildcardUpperTypeVariable() { | |
| throw new RuntimeException(); | |
| } | |
| } | |
| Nested<? extends String> testDirect(Nested<? extends String> receiver) { | |
| // BUG: Diagnostic contains: incompatible types | |
| return receiver.wildcardUpperTypeVariable(); | |
| } | |
| Nested<? extends String> testWithSelf(Nested<? extends String> receiver) { | |
| // BUG: Diagnostic contains: incompatible types | |
| return receiver.self().wildcardUpperTypeVariable(); | |
| } | |
| Nested<? extends String> testWithVar(Nested<? extends String> receiver) { | |
| var local = receiver; | |
| // BUG: Diagnostic contains: incompatible types | |
| return local.wildcardUpperTypeVariable(); | |
| } | |
| } | |
| """) | |
| .doTest(); | |
| } |
🤖 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/WildcardTests.java` around
lines 435 - 472, Add Javadoc to the non-trivial test method
wildcardCaptureRestoresConcreteAnnotatedBound, briefly documenting the
wildcard-capture regression scenario it covers and the expected diagnostic
behavior. Leave the test implementation and assertions unchanged.
Source: Coding guidelines
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## library-models-captures #1667 +/- ##
==========================================================
Coverage ? 87.75%
Complexity ? 3138
==========================================================
Files ? 109
Lines ? 10619
Branches ? 2147
==========================================================
Hits ? 9319
Misses ? 616
Partials ? 684 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
1de4d06 to
4c228f2
Compare
1eeae57 to
78d77c1
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/WildcardTests.java (1)
410-411: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winAdd Javadoc to both new regression tests.
Both methods test captured wildcard annotation restoration. Add a short Javadoc comment that states the tested contract.
nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java#L410-L411: document nested-nullability restoration on a captured wildcard return.test-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java#L572-L573: document modeled nullable-bound restoration across receiver paths.As per coding guidelines, “Add Javadoc to every non-trivial method, including private methods.”
🤖 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/WildcardTests.java` around lines 410 - 411, Add short Javadoc comments to both regression test methods: nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java:410-411 should document nested-nullability restoration on a captured wildcard return, and test-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java:572-573 should document modeled nullable-bound restoration across receiver paths.Source: Coding guidelines
🤖 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/WildcardTests.java`:
- Around line 410-411: Add short Javadoc comments to both regression test
methods:
nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java:410-411
should document nested-nullability restoration on a captured wildcard return,
and
test-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java:572-573
should document modeled nullable-bound restoration across receiver paths.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 6bc57294-119d-4b91-9712-959960df12f2
📒 Files selected for processing (3)
nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.javanullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.javatest-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java
The fix in #1666 missed a case that has impacts outside of library models as well. See the new test
WildcardTests.annotationRestoredFromUpperBoundToCapturedWildcard. ThetestWithSelfcase was handled before, but nottestDirectortestWithVar.Summary by CodeRabbit
Bug Fixes
Tests