Skip to content

Follow-on fix for restoring annotation on captured type wildcards - #1667

Open
msridhar wants to merge 3 commits into
library-models-capturesfrom
follow-up-on-wildcard-library-models
Open

Follow-on fix for restoring annotation on captured type wildcards#1667
msridhar wants to merge 3 commits into
library-models-capturesfrom
follow-up-on-wildcard-library-models

Conversation

@msridhar

@msridhar msridhar commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

The fix in #1666 missed a case that has impacts outside of library models as well. See the new test WildcardTests.annotationRestoredFromUpperBoundToCapturedWildcard. The testWithSelf case was handled before, but not testDirect or testWithVar.

Summary by CodeRabbit

  • Bug Fixes

    • Improved nullability handling for captured wildcard types with annotated upper bounds.
    • Prevented incorrect compatibility results for nested wildcard types across direct calls, chained calls, and local variables.
  • Tests

    • Added regression coverage for multiple wildcard-capture invocation patterns.

@msridhar

msridhar commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

visitCapturedType restores nullability annotations for captured extends wildcards when the source type is non-wildcard. Tests cover direct, self()-chained, and local-variable invocation paths and verify incompatible-type diagnostics.

Possibly related issues

  • uber/NullAway issue 1656 — Concerns captured-wildcard annotation restoration in TypeSubstitutionUtils.

Possibly related PRs

  • uber/NullAway#1666 — Modifies captured-wildcard restoration in TypeSubstitutionUtils and adds related regression coverage.
  • uber/NullAway#1655 — Updates related visitCapturedType nullability-restoration logic.
  • uber/NullAway#1454 — Introduces related wildcard upper-bound nullability restoration in TypeSubstitutionUtils.

Suggested reviewers: lazaroclapp, yuxincs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the follow-on fix for restoring annotations on captured type wildcards.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch follow-up-on-wildcard-library-models

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1de4d06 and 7920df9.

📒 Files selected for processing (3)
  • nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java
  • test-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java

Comment on lines +435 to +472
@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();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

Suggested change
@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

@msridhar
msridhar requested a review from lazaroclapp July 31, 2026 01:11
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (library-models-captures@4c228f2). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@msridhar
msridhar force-pushed the library-models-captures branch from 1de4d06 to 4c228f2 Compare August 2, 2026 02:09
@msridhar
msridhar force-pushed the follow-up-on-wildcard-library-models branch from 1eeae57 to 78d77c1 Compare August 2, 2026 02:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Add 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1eeae57 and 78d77c1.

📒 Files selected for processing (3)
  • nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java
  • test-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant