Skip to content

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

Open
msridhar wants to merge 14 commits into
masterfrom
follow-up-on-wildcard-library-models
Open

Follow-on fix for restoring annotation on captured type wildcards#1667
msridhar wants to merge 14 commits into
masterfrom
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.
    • Improved diagnostic accuracy when wildcard types conflict with nullable type-variable bounds.
  • Tests

    • Added regression coverage for direct, chained, and local-variable wildcard-capture invocation patterns.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

visitCapturedType restores annotations for captured extends wildcards when the source type is non-wildcard. Tests cover direct, self()-chained, and local-variable calls. Each path verifies an incompatible-type diagnostic.

Possibly related issues

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

Possibly related PRs

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
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.
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 annotation restoration on captured type wildcards.
✨ 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@2449fdd). Learn more about missing BASE report.

Additional details and impacted files
@@                    Coverage Diff                     @@
##             library-models-captures    #1667   +/-   ##
==========================================================
  Coverage                           ?   87.67%           
  Complexity                         ?     3138           
==========================================================
  Files                              ?      109           
  Lines                              ?    10619           
  Branches                           ?     2147           
==========================================================
  Hits                               ?     9310           
  Misses                             ?      628           
  Partials                           ?      681           

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

@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

@msridhar
msridhar force-pushed the library-models-captures branch from 4c228f2 to 2449fdd Compare August 4, 2026 20:37
@msridhar
msridhar force-pushed the follow-up-on-wildcard-library-models branch from 78d77c1 to f872e52 Compare August 4, 2026 20:37

@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-433: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add Javadoc to the new regression test methods.

These methods contain compiler regression fixtures and are non-trivial. Add Javadoc that states the regression condition and expected analysis result.

  • nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java#L410-L433: Document the captured wildcard return with nested nullable type arguments.
  • nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java#L1209-L1237: Document the accepted reactive response pipeline from issue 1671.
  • test-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java#L572-L620: Document modeled captured wildcard bounds across direct, chained, and local receiver paths.
Proposed Javadoc
diff --git a/nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java b/nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java
@@
+  /** Verifies nested nullable type arguments are retained on a captured wildcard return. */
   `@Test`
   public void wildcardCaptureReturnPreservesNestedNullability() {
@@
+  /** Verifies JSpecify analysis accepts the reactive response pipeline from issue 1671. */
   `@Test`
   public void issue1671() {

diff --git a/test-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java b/test-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java
@@
+  /** Verifies modeled nullable bounds on captured wildcards across receiver paths. */
   `@Test`
   public void nestedWildcardWithCapturedTypeVariableBound() {

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 - 433, Add Javadoc describing the regression condition and expected
analysis result for the test method at
nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java:410-433,
specifically captured wildcard returns with nested nullable type arguments. Also
document the accepted reactive response pipeline test at
nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java:1209-1237
and the modeled captured wildcard bounds across direct, chained, and local
receiver paths in
nullaway/test-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java:572-620;
do not alter test behavior.

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-433: Add Javadoc describing the regression condition and
expected analysis result for the test method at
nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java:410-433,
specifically captured wildcard returns with nested nullable type arguments. Also
document the accepted reactive response pipeline test at
nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java:1209-1237
and the modeled captured wildcard bounds across direct, chained, and local
receiver paths in
nullaway/test-library-models/src/test/java/com/uber/nullaway/CustomLibraryModelsTests.java:572-620;
do not alter test behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 26ce5419-b6c5-4d59-beb6-4eff303b0dde

📥 Commits

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

📒 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

// BUG: Diagnostic contains: incompatible types
return local.wildcardUpperTypeVariable();
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we already have it somewhere, but, if not, do we care to add the case where the return of the test method is Nested<? extends @Nullable String> and this should emit no error?

@msridhar
msridhar force-pushed the library-models-captures branch from 2449fdd to 6ea8dce Compare August 5, 2026 05:36
Base automatically changed from library-models-captures to master August 5, 2026 05:51
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.

2 participants