Skip to content

Comments

JSpecify: assume NONNULL in generic method inference for unconstrained type variables#1471

Merged
msridhar merged 5 commits intomasterfrom
issue-1453
Feb 16, 2026
Merged

JSpecify: assume NONNULL in generic method inference for unconstrained type variables#1471
msridhar merged 5 commits intomasterfrom
issue-1453

Conversation

@msridhar
Copy link
Collaborator

@msridhar msridhar commented Feb 15, 2026

Fixes #1453

I think a change in 0.13.0 made it more important that we have some solution for all type variables of a method.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of generic methods so unconstrained type parameters are treated as non-null, enhancing nullability inference for generics.
  • Tests

    • Added a new test validating helper usage and nullability inference in generic method scenarios.

@msridhar msridhar requested a review from yuxincs February 15, 2026 02:29
@msridhar
Copy link
Collaborator Author

@agrieve is there any way you could test this fixes the issue for Chromium using a snapshot build?

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 15, 2026

Walkthrough

The PR changes generic type-variable inference in GenericsChecks.java to copy the solver result into a mutable HashMap, then iterates the method's type parameters and inserts a NONNULL mapping for any unconstrained type variables (with comments explaining the choice). It also adds a new test issue1453 in GenericMethodTests.java that exercises an assumeNonNull helper in a foreach scenario to validate the updated inference behavior.

Possibly related PRs

Suggested labels

jspecify

Suggested reviewers

  • yuxincs
  • lazaroclapp
🚥 Pre-merge checks | ✅ 5 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: treating unconstrained type variables as NONNULL in generic method inference for JSpecify processing.
Linked Issues check ✅ Passed The code changes address issue #1453 by modifying type inference to treat unconstrained generic method type variables as NONNULL, enabling helpers like assumeNonNull() to work without explicit @NonNull annotations.
Out of Scope Changes check ✅ Passed All changes are scoped to addressing the regression: GenericsChecks.java modifications handle type variable inference, and GenericMethodTests.java adds a test case validating the fix.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issue-1453

No actionable comments were generated in the recent review. 🎉


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java`:
- Around line 1536-1547: Remove the unused import of
org.jetbrains.annotations.Contract from the test source where the NullUtil class
and assumeNonNull method are defined; locate the import line in the
NullUtil.java test snippet and delete the Contract import so only the necessary
imports (org.jspecify.annotations.NullMarked and
org.jspecify.annotations.Nullable) remain.

msridhar and others added 2 commits February 14, 2026 18:33
…dTests.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Feb 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.49%. Comparing base (bd25690) to head (84d5fa3).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1471      +/-   ##
============================================
+ Coverage     88.48%   88.49%   +0.01%     
- Complexity     2723     2725       +2     
============================================
  Files            99       99              
  Lines          9073     9076       +3     
  Branches       1812     1813       +1     
============================================
+ Hits           8028     8032       +4     
  Misses          518      518              
+ Partials        527      526       -1     

☔ 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 enabled auto-merge (squash) February 16, 2026 06:17
@msridhar msridhar merged commit 1e83ccf into master Feb 16, 2026
12 checks passed
@msridhar msridhar deleted the issue-1453 branch February 16, 2026 06:29
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.

assumeNonNull() no longer works in all spots

2 participants