Skip to content

Cover anonymous class type arguments and modeled call-site returns - #1777

Merged
msridhar merged 2 commits into
uber:masterfrom
vlsi:tests/anonymous-class-and-astubx-callsite
Sep 2, 2026
Merged

msridhar merged 2 commits into
uber:masterfrom
vlsi:tests/anonymous-class-and-astubx-callsite

Conversation

@vlsi

@vlsi vlsi commented Aug 29, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up tests for #1746, which #1722 fixed. Offered per #1746 (comment)

Why

overrideExplicitlyTypedAnonymousClassWithNestedGenericTypes, added by #1722, covers an anonymous class that implements an interface at @Nullable String and overrides List<T>. The diamond form and an array element take paths that test does not reach, and #1746 reported both as false positives.

#1722 also stopped nullableReturns() from stripping whitespace out of astubx signatures, which lets 36 entries of jspecify-jdk.astubx match for the first time — every one of them differing only by a space inside a wildcard bound such as ? super K. Those entries feed hasNullableReturn at every call site, not only at override checks, and mapComputeOverrideUsesJSpecifyModel discarded the result of map.compute(...), so nothing pinned the call-site direction.

What

Two new tests in GenericsTests: a diamond anonymous class whose overrides wrap the type variable in List<T>, and an anonymous class in both the explicit and the diamond form whose overrides wrap it in an array.

mapComputeOverrideUsesJSpecifyModel now also dereferences the result of map.compute(...). The bare call stays: an unmarked line asserts that no diagnostic fires there, which is how the existing test pins that a BiFunction<String, @Nullable String, @Nullable String> argument is accepted. A // BUG: marker on that line would have consumed any other diagnostic it produced.

Optional.orElseGet is the other way to pin the call-site direction, and this change leaves it alone. JSpecifyLibraryModelsTests.optionalOrElseGet passes today, but LibraryModelsHandler still carries the hand-written model for that method commented out under #1616, so removing the @Ignore is a call for a maintainer rather than for this pull request.

How to verify

./gradlew :nullaway:test --tests "com.uber.nullaway.jspecify.GenericsTests" --tests "com.uber.nullaway.JSpecifyJDKModelsTest"

Every assertion here fails at 70da029, the commit before #1722. The two array blocks needed checking one marker at a time, because the harness stops at the first unmarked line that carries an error.

Summary by CodeRabbit

  • Bug Fixes
    • Improved nullability analysis for Map.compute results, correctly identifying values that may be null.
    • Preserved @Nullable annotations when analyzing anonymous classes with nested generic types, diamond syntax, and arrays of type variables.

uber#1746 reported that an anonymous class dropped the @nullable on its
supertype's type argument, and uber#1722 fixed it. The test that PR added
covers the interface form with one level of nesting, so the diamond
form and an array element are still unpinned.

uber#1722 also changed how astubx signatures are normalized, which lets 36
entries of jspecify-jdk.astubx match for the first time. Those entries
feed hasNullableReturn at every call site, and callSite discarded the
result of map.compute, so only the override direction was pinned.

Every case here fails at 70da029, the commit before uber#1722.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f5d7c0e5-eff3-416c-b441-340d7726eda4

📥 Commits

Reviewing files that changed from the base of the PR and between 915b287 and 2206cd3.

📒 Files selected for processing (2)
  • nullaway/src/test/java/com/uber/nullaway/JSpecifyJDKModelsTest.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


Walkthrough

Expanded JSpecify test coverage in two areas. The JDK model test now checks that the result of Map.compute is treated as nullable. GenericsTests adds coverage for nullable type arguments in diamond anonymous classes with nested generic types and for array types based on nullable type variables. The tests verify accepted nullable overrides and diagnostics for mismatched non-nullable overrides.

Suggested reviewers: msridhar, dbwiddis

Merge Risk: ⚪ Minimal · up to 2206c

This change expands regression coverage for existing nullability behavior without modifying shipped code or runtime behavior; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. 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.
Title check ✅ Passed The title clearly summarizes both main changes: coverage for anonymous class type arguments and modeled call-site returns.
Description check ✅ Passed The description directly explains the added tests, the modeled return-value coverage, the issue context, and the verification command.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@msridhar msridhar left a comment

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.

Thanks!

@msridhar
msridhar enabled auto-merge (squash) September 2, 2026 01:17
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.65%. Comparing base (c1221cb) to head (18f3fb2).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1777   +/-   ##
=========================================
  Coverage     87.65%   87.65%           
  Complexity     3291     3291           
=========================================
  Files           109      109           
  Lines         11084    11084           
  Branches       2247     2247           
=========================================
  Hits           9716     9716           
  Misses          641      641           
  Partials        727      727           

☔ 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 merged commit b5aad0d into uber:master Sep 2, 2026
14 checks passed
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