Skip to content

Fix issue with reading annotations on record constructor parameters due to javac bug - #1636

Merged
msridhar merged 3 commits into
masterfrom
record-bug
Jul 18, 2026
Merged

msridhar merged 3 commits into
masterfrom
record-bug

Conversation

@msridhar

@msridhar msridhar commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

Due to a bug in javac in JDK 17-26 (fixed in openjdk/jdk#29928), sometimes type use annotations appear on record constructor parameters with position FIELD (specifically, when a compact record constructor is used). We work around that bug by also looking for type use annotations on the type of the symbol for the parameter. Previously this would not work for parameters from bytecode, but it works now on the most recent versions of JDK 17 and 21 with the flag -XDaddTypeAnnotationsToSymbol=true passed to javac. As it requires a significant hack to fix this otherwise, and it only impacts checking outside JSpecify mode, I'm not inclined to try to fix for when -XDaddTypeAnnotationsToSymbol=true is not passed.

Fixes #1631

@msridhar

Copy link
Copy Markdown
Collaborator Author

This change is part of the following stack:

Change managed by git-spice.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Updates getAllAnnotationsForParameter to collect type-use annotations directly from a parameter’s declared type, retain legacy raw type attributes, remove duplicates, and combine them with declaration annotations. Adds tests for record constructor parameters using byte @nullable[] under JSpecify and verifies diagnostics for invalid null arguments.

Possibly related PRs

  • uber/NullAway#1484: Relies on NullabilityUtil.getAllAnnotationsForParameter for type-use annotation inspection in varargs nullness handling.
  • uber/NullAway#1632: Also refines parameter annotation collection and adds JSpecify record-constructor coverage.

Suggested labels: jspecify

Suggested reviewers: lazaroclapp, yuxincs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: reading annotations on record constructor parameters to work around a javac bug.
✨ 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 record-bug

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java`:
- Around line 368-370: Update the isDirectTypeUseAnnotation call in the
parameter annotation check to pass varSymbol instead of symbol, so nesting
checks evaluate the parameter’s type. Remove the redundant NullabilityUtil.
qualifier since the call is within NullabilityUtil.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 229808c0-31cf-4af2-93d9-41be2b64040b

📥 Commits

Reviewing files that changed from the base of the PR and between 43a78f3 and ab1a1da.

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

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.21%. Comparing base (43a78f3) to head (ab1a1da).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1636      +/-   ##
============================================
+ Coverage     88.20%   88.21%   +0.01%     
- Complexity     3075     3076       +1     
============================================
  Files           105      105              
  Lines         10293    10296       +3     
  Branches       2087     2087              
============================================
+ Hits           9079     9083       +4     
  Misses          573      573              
+ Partials        641      640       -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.

@github-actions

Copy link
Copy Markdown

Main Branch:

Benchmark                          Mode  Cnt   Score   Error  Units
AutodisposeBenchmark.compile      thrpt   25  10.483 ± 0.112  ops/s
CaffeineBenchmark.compile         thrpt   25   2.310 ± 0.014  ops/s
DFlowMicroBenchmark.compile       thrpt   25  40.977 ± 0.222  ops/s
NullawayReleaseBenchmark.compile  thrpt   25   1.677 ± 0.018  ops/s

With This PR:

Benchmark                          Mode  Cnt   Score   Error  Units
AutodisposeBenchmark.compile      thrpt   25  10.524 ± 0.060  ops/s
CaffeineBenchmark.compile         thrpt   25   2.283 ± 0.009  ops/s
DFlowMicroBenchmark.compile       thrpt   25  41.079 ± 0.219  ops/s
NullawayReleaseBenchmark.compile  thrpt   25   1.649 ± 0.020  ops/s

@msridhar
msridhar merged commit 78d9994 into master Jul 18, 2026
13 of 15 checks passed
@msridhar
msridhar deleted the record-bug branch July 18, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

2 participants