Skip to content

Fix false positives in override checking of methods with PolyNull models - #2143

Draft
msridhar wants to merge 2 commits into
masterfrom
fix/polynull-override-warning-2142
Draft

msridhar wants to merge 2 commits into
masterfrom
fix/polynull-override-warning-2142

Conversation

@msridhar

@msridhar msridhar commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

When checking an override of a method where the overridden method has @PolyNull models (like computeIfAbsent), ignore all @PolyNull locations in the override check. This removes false positives in checking; it does not do full checking of @PolyNull behavior in the override. This is achieved by "masking" the @PolyNull locations using annotations on a copy of the method type; see OverrideNullnessMask.

Fixes #2142

Summary by CodeRabbit

  • Bug Fixes
    • Corrected nullness compatibility checks for method overrides involving polymorphic nullness. Modeled locations are now treated as nullable when comparing declarations, including inherited locations and generic or nested types.
    • Override checks do not validate whether implementations preserve linked-nullness relationships; call-specific nullness inference remains unchanged.

@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

getModeledOverriddenMethodType now applies synthetic @Nullable annotations to modeled PolyNull locations when checking override declarations. Documentation describes this treatment and states that the check does not verify whether an implementation preserves the linked-nullness relationship. New tests cover Map.computeIfAbsent overrides and inherited PolyNull locations, including unrelated nullness locations.

Possibly related PRs

  • uber/NullAway#2141: Adds a PolyNull model for Map.compute, which the override compatibility change can use when checking Map.compute overrides.

Suggested reviewers: vlsi, subhramit

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to 0581c

No concrete merge-blocking issue is established. The change addresses false-positive override warnings while explicitly leaving full PolyNull implementation verification out of scope.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title names the main change: it fixes false positives in override checking for methods that have PolyNull library models. The raw summary shows the GenericsChecks and LibraryModels changes treat P…
Linked Issues check Passed Directly linked issue #2142 requires that override declarations of PolyNull-modeled JDK methods, such as Map.computeIfAbsent and Map.compute, do not receive an unconditional non-null-superclass-return…
Out of Scope Changes check Passed The changed areas are the override-declaration check in GenericsChecks (the fix), a Javadoc paragraph in LibraryModels that documents the new override behavior, and new tests in PolyNullLibraryModelsT…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Description check Passed The description states that @PolyNull locations in an overridden method are ignored during the override check to remove false positives, and that this is done by masking those locations on a copy of t…
Full details: Title check

Explanation

The title names the main change: it fixes false positives in override checking for methods that have PolyNull library models. The raw summary shows the GenericsChecks and LibraryModels changes treat PolyNull locations in overridden methods as @Nullable, and the tests cover Map.computeIfAbsent overrides. The title is specific and matches the changeset.

Full details: Linked Issues check

Explanation

Directly linked issue #2142 requires that override declarations of PolyNull-modeled JDK methods, such as Map.computeIfAbsent and Map.compute, do not receive an unconditional non-null-superclass-return warning. The PR changes GenericsChecks.getModeledOverriddenMethodType to apply @Nullable to the PolyNull locations of the overridden method (per the AI-generated summary; the source diff could not be read, so this rests on the summary and the tests). The new test mapComputeIfAbsentOverrideAcceptsNullableModelLocations in PolyNullLibraryModelsTests covers a @Nullable return override (accepted), a non-null return override (accepted), and a narrowed callback parameter (still reported). The new test overrideDeclarationsApplyOnlyInheritedPolyNullLocations shows that a non-null parameter at a fixed, non-PolyNull location still reports, and that an unmodeled non-null return still reports. The issue's Map.compute example depends on the #2140 model. This PR adds no Map.compute-specific test and does not show that model in the changed files. The generic fix should cover compute once that model is present, but this was not verified. The LibraryModels Javadoc states the limit: the override check does not verify that the implementation preserves the PolyNull contract, as the issue requests. The tests were not executed during this review.

Full details: Out of Scope Changes check

Explanation

The changed areas are the override-declaration check in GenericsChecks (the fix), a Javadoc paragraph in LibraryModels that documents the new override behavior, and new tests in PolyNullLibraryModelsTests. Each change connects directly to #2142. The Javadoc and tests describe the limited scope the issue asks for. No unrelated change was identified in the reviewed evidence. The GenericsChecks source diff could not be read, so this verdict relies on its AI-generated summary and the test expectations.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files.

Full details: Description check

Explanation

The description states that @PolyNull locations in an overridden method are ignored during the override check to remove false positives, and that this is done by masking those locations on a copy of the method type via OverrideNullnessMask. This matches the changeset, which adds PolyNull-to-@nullable handling in GenericsChecks.getModeledOverriddenMethodType, documentation in LibraryModels, and computeIfAbsent override tests. It also references issue #2142, which the objectives confirm. The description is specific and on-topic.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 13392cb and 0581c61.

Files selected for processing: 3

  • nullaway/src/main/java/com/uber/nullaway/LibraryModels.java
  • nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/PolyNullLibraryModelsTests.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@msridhar
msridhar marked this pull request as draft November 8, 2026 02:32
@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.50%. Comparing base (13392cb) to head (b73e6c1).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2143      +/-   ##
============================================
+ Coverage     89.39%   89.50%   +0.10%     
  Complexity       38       38              
============================================
  Files           119      120       +1     
  Lines         13024    13060      +36     
  Branches       2671     2677       +6     
============================================
+ Hits          11643    11689      +46     
+ Misses          623      614       -9     
+ Partials        758      757       -1     

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

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.

PolyNull library models cause false-positive nullable return warnings on override declarations

1 participant