Skip to content

Detect and warn on annotations directly on wildcard types#1579

Merged
msridhar merged 7 commits into
masterfrom
annotation-on-wildcard
May 25, 2026
Merged

Detect and warn on annotations directly on wildcard types#1579
msridhar merged 7 commits into
masterfrom
annotation-on-wildcard

Conversation

@msridhar
Copy link
Copy Markdown
Collaborator

@msridhar msridhar commented May 16, 2026

See https://jspecify.dev/docs/spec/#recognized-type-use. I've seen this issue in real code, and developers may be confused if we just ignore, so I think we should give a warning. We should consider warning on other unrecognized locations for nullness annotations when in JSpecify mode.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added detection and reporting for invalid nullness annotations placed on wildcard type arguments in JSpecify mode.
  • Tests

    • Added test coverage for wildcard annotation validation.

Review Change Stack

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.19%. Comparing base (c183d49) to head (06f6580).

Files with missing lines Patch % Lines
...ava/com/uber/nullaway/generics/GenericsChecks.java 78.94% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1579      +/-   ##
============================================
- Coverage     88.20%   88.19%   -0.02%     
- Complexity     2938     2947       +9     
============================================
  Files           104      104              
  Lines          9819     9842      +23     
  Branches       1977     1982       +5     
============================================
+ Hits           8661     8680      +19     
- Misses          558      560       +2     
- Partials        600      602       +2     

☔ View full report in Codecov by Sentry.
📢 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 requested a review from lazaroclapp May 16, 2026 21:24
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from 02032b9 to 6b46cae Compare May 16, 2026 23:28
@msridhar msridhar force-pushed the annotation-on-wildcard branch from d0cc24e to f4fc049 Compare May 16, 2026 23:28
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from 6b46cae to e046e3c Compare May 17, 2026 18:48
@msridhar msridhar force-pushed the annotation-on-wildcard branch from f4fc049 to 40e3a5b Compare May 17, 2026 18:48
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from e046e3c to 5d6301c Compare May 18, 2026 20:36
@msridhar msridhar force-pushed the annotation-on-wildcard branch from 40e3a5b to 6336f26 Compare May 18, 2026 20:36
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from 5d6301c to 9c7885b Compare May 18, 2026 20:56
@msridhar msridhar force-pushed the annotation-on-wildcard branch from 6336f26 to a86bdaa Compare May 18, 2026 20:56
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from 9c7885b to b365629 Compare May 20, 2026 13:50
@msridhar msridhar force-pushed the annotation-on-wildcard branch from a86bdaa to 7caffde Compare May 20, 2026 13:50
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from b365629 to 8eefd6b Compare May 22, 2026 02:09
@msridhar msridhar force-pushed the annotation-on-wildcard branch from 7caffde to 678cd58 Compare May 22, 2026 02:09
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from 8eefd6b to f4da62e Compare May 23, 2026 20:14
@msridhar msridhar force-pushed the annotation-on-wildcard branch from 678cd58 to d1a13d3 Compare May 23, 2026 20:14
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from f4da62e to a877763 Compare May 23, 2026 22:29
@msridhar msridhar force-pushed the annotation-on-wildcard branch from d1a13d3 to 5718e6f Compare May 23, 2026 22:29
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from a877763 to d790baf Compare May 23, 2026 23:56
@msridhar msridhar force-pushed the annotation-on-wildcard branch from 5718e6f to 152e17c Compare May 23, 2026 23:56
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from d790baf to d9c9900 Compare May 24, 2026 00:04
@msridhar msridhar force-pushed the annotation-on-wildcard branch from 152e17c to 94591a0 Compare May 24, 2026 00:04
Copy link
Copy Markdown
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

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

Makes sense! LGTM!

@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from d9c9900 to 4f9db4f Compare May 25, 2026 16:59
@msridhar msridhar force-pushed the annotation-on-wildcard branch from 94591a0 to aa0dbfb Compare May 25, 2026 16:59
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from 4f9db4f to 86870e5 Compare May 25, 2026 17:32
@msridhar msridhar force-pushed the annotation-on-wildcard branch from aa0dbfb to 44c56e1 Compare May 25, 2026 17:32
@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from 86870e5 to 5244672 Compare May 25, 2026 18:04
@msridhar msridhar force-pushed the annotation-on-wildcard branch from 44c56e1 to 1265591 Compare May 25, 2026 18:04
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 69b5308b-848d-4b10-ab45-524e6703159f

📥 Commits

Reviewing files that changed from the base of the PR and between c183d49 and 9e0debd.

📒 Files selected for processing (4)
  • nullaway/src/main/java/com/uber/nullaway/ErrorMessage.java
  • nullaway/src/main/java/com/uber/nullaway/NullAway.java
  • nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java

Walkthrough

This PR adds detection and reporting of nullness annotations (@Nullable, @NonNull) placed directly on wildcard type parameters in JSpecify mode, which is not a legal annotation location. A new error message type is defined, core detection logic is implemented in GenericsChecks, integration is wired through NullAway's AnnotatedTypeTreeMatcher interface, and comprehensive tests validate the behavior across valid and invalid wildcard annotation scenarios.

Possibly related PRs

  • uber/NullAway#1361: Wildcard test reorganization in the same test suite where the new nullableOnWildcard test is added.
  • uber/NullAway#1256: Refactored NullAwayGenericsChecks integration patterns that align with the wiring approach used here.
  • uber/NullAway#1558: Overlapping JSpecify wildcard nullness handling in GenericsChecks and WildcardTests.

Suggested reviewers

  • lazaroclapp
  • yuxincs
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% 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 accurately summarizes the main change: detecting and warning on annotations placed directly on wildcard types, which is the primary focus across all modified files.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch annotation-on-wildcard

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 and usage tips.

@msridhar msridhar force-pushed the wildcard-upper-bound-type-var-unmarked branch from 5244672 to fda7118 Compare May 25, 2026 18:19
@msridhar msridhar force-pushed the annotation-on-wildcard branch from 1265591 to 4e21ef7 Compare May 25, 2026 18:19
Base automatically changed from wildcard-upper-bound-type-var-unmarked to master May 25, 2026 18:36
@msridhar msridhar force-pushed the annotation-on-wildcard branch from 4e21ef7 to 9e0debd Compare May 25, 2026 18:36
@msridhar msridhar enabled auto-merge (squash) May 25, 2026 18:37
@msridhar msridhar merged commit 31b14ce into master May 25, 2026
8 of 12 checks passed
@msridhar msridhar deleted the annotation-on-wildcard branch May 25, 2026 19:04
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