Skip to content

Fix incorrect @NonNull requirement for nullable record components with compact constructors - #1632

Closed
dev-kvt wants to merge 1 commit into
uber:masterfrom
dev-kvt:fix-record-constructor-nullability
Closed

dev-kvt wants to merge 1 commit into
uber:masterfrom
dev-kvt:fix-record-constructor-nullability

Conversation

@dev-kvt

@dev-kvt dev-kvt commented Jul 16, 2026 •

Copy link
Copy Markdown

Fixes #1631

Summary

Fix a false positive where NullAway incorrectly reports that a @NonNull value is required for a record component annotated with a type-use @Nullable annotation when the record defines a compact (custom) constructor.

Root Cause

When analyzing canonical record constructors, NullAway only considered annotations attached directly to the constructor parameter. For canonical record constructors, the corresponding record component also carries relevant nullability annotations, but these were not being considered during analysis, causing the @Nullable annotation to be missed in this scenario.

Fix

Update NullabilityUtil.getAllAnnotationsForParameter to detect canonical record constructors and retrieve annotations from the corresponding record component in addition to the constructor parameter. This ensures that declaration and type-use annotations on record components are available during nullability analysis.

Tests

Added a regression test that reproduces the issue using a record with a compact constructor and a type-use @Nullable array component. The test fails without the fix and passes with the fix.

Summary by CodeRabbit

  • Bug Fixes

    • Improved nullability analysis for record constructors, including compact constructors.
    • Annotation handling now correctly accounts for annotations declared on record components and their types.
  • Tests

    • Added coverage for nullable array components in records with compact constructors.

@CLAassistant

CLAassistant commented Jul 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jul 16, 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

Run ID: 7659a774-50d6-4685-97ff-3f78853e4dd5

📥 Commits

Reviewing files that changed from the base of the PR and between 77726c5 and 9e049a4.

📒 Files selected for processing (2)
  • nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/JSpecifyArrayTests.java

Walkthrough

getAllAnnotationsForParameter now collects parameter declaration and direct type-use annotations, then adds annotations from matching record components for canonical record constructors. New helpers detect canonical constructors and compare parameter types while ignoring type annotations. A JSpecify test covers a compact record constructor with a nullable array component.

Suggested labels: jspecify

Suggested reviewers: msridhar, yuxincs, lazaroclapp

🚥 Pre-merge checks | ✅ 5
✅ 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 clearly matches the fix for nullable record components in compact constructors.
Linked Issues check ✅ Passed The annotation lookup change and regression test address the reported false positive for nullable record array components with custom constructors.
Out of Scope Changes check ✅ Passed The PR changes stay focused on record-constructor nullability handling and the related regression test.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@dev-kvt
dev-kvt marked this pull request as draft July 17, 2026 11:29
@dev-kvt
dev-kvt marked this pull request as ready for review July 17, 2026 11:29
@msridhar

Copy link
Copy Markdown
Collaborator

This is an invalid fix for this issue

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.

False positive with JSpecify nullable array in record with a custom constructor

3 participants