Skip to content

Read nullable fields from JSpecify JDK models into astubx - #1901

Merged
msridhar merged 10 commits into
apache:masterfrom
subhramit:jdk-models-nullable-fields
Oct 4, 2026
Merged

msridhar merged 10 commits into
apache:masterfrom
subhramit:jdk-models-nullable-fields

Conversation

@subhramit

@subhramit subhramit commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1862

Serialize top-level nullable fields from JSpecify JDK sources into astubx v2 and load them as library models.
Regenerate the bundled JDK astubx.

Before pressing the "Create Pull Request" button, please provide the following:

  • A description about what and why you are contributing, even if it's trivial.

  • The issue number(s) or PR number(s) in the description if you are contributing in response to those.

  • If applicable, unit tests.

AI usage - Zed + GPT 5.6 Sol. I have manually verified all code and run all tests.

Summary by CodeRabbit

  • New Features
    • Library models now preserve nullable field annotations, including fields in nested classes, so nullability checks can flag unsafe dereferences.
    • Generated annotation files include nullable-field information when available.
  • Compatibility
    • Existing version 1 annotation files remain supported; version 2 files can also be read.
  • Tests
    • Added coverage for nullable and non-null fields, nested classes, and nullability diagnostics from library models.

Signed-off-by: subhramit <subhramit.bb@live.in>
Signed-off-by: subhramit <subhramit.bb@live.in>
Signed-off-by: subhramit <subhramit.bb@live.in>
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: uber/NullAway/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 4584b70e-36d8-462c-8fe7-a4891db56ad2

📥 Commits

Reviewing files that changed from the base of the PR and between 7f92fef and 876d233.

📒 Files selected for processing (12)
  • jdk-annotations/astubx-generator/src/main/java/com/uber/nullaway/jdkannotations/AstubxGenerator.java
  • jdk-annotations/astubx-generator/src/test/java/com/uber/nullaway/jdkannotations/AstubxTest.java
  • jdk-annotations/jdk-integration-test/src/test/java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.java
  • jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/FieldAnnotation.java
  • jdk-annotations/test-unannotated/src/main/java/com/uber/nullaway/jdkannotations/FieldAnnotation.java
  • jdk-javac-plugin/src/main/java/com/uber/nullaway/javacplugin/NullnessAnnotationSerializer.java
  • jdk-javac-plugin/src/test/java/com/uber/nullaway/javacplugin/NullnessAnnotationSerializerTest.java
  • library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/StubxWriter.java
  • nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java
  • nullaway/src/main/java/com/uber/nullaway/handlers/StubxCacheUtil.java
  • nullaway/src/main/resources/jspecify-jdk.astubx
  • nullaway/src/test/java/com/uber/nullaway/JSpecifyJDKModelsTest.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.


Walkthrough

The javac serializer now records eligible nullable fields and their enclosing classes. The astubx generator and writer carry this data into version 2 files, while retaining version 1 output when no nullable fields are present. The cache reads nullable-field records from version 2 files, and the library-model handler adds them to stubx-derived models. Tests cover serialization, file generation, and nullable-field diagnostics.

Suggested reviewers: msridhar

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 876d2

The change carries nullable field annotations into library models while preserving version 1 compatibility. No actionable merge-blocking issue is established; merge after normal checks pass.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 876d2

The change extends the analysis-data format without demonstrating a new untrusted entry point or privilege increase. Older consumers cannot read files using the new version, and damaged-input recovery and packaged-data integrity remain partially assessed.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A party controlling model resources or the compiler's provider classpath could influence matching field facts in checker invocations that load those resources. The inspected paths do not establish lower-privilege access, tenant isolation effects or runtime application privilege gains; deployment ownership remains unknown.

Trust Boundaries and Controls

  • observed — Direct LibraryModels providers already had nullable-field authority before this PR: the base combined provider field sets and consumed them through the same field callbacks. Unfiltered provider-field aggregation therefore predates this change rather than constituting a newly bypassed control.
  • observed — Bundled JDK models remain configuration-gated classloader resources, published through an immutable holder. External JarInfer resources remain separately gated and discovered through existing service providers. The resource-opening helper receives URLs from those classloader lookups.

Resilience and Maintainability Implications

  • observed — The new field cache is mutable, exposed by its getter and populated incrementally. Repeated loads union field pairs, while interrupted parsing can leave partial cache contents. This extends the existing parser ownership pattern; concurrent use and reuse after failure are not demonstrated production behaviors.
  • inferred — Bundled JDK parse failures prevent immutable publication, and service-provider IO failures abort discovery. Android model IO failures are instead caught before immutable conversion, so a truncated version 2 Android resource could publish incomplete field metadata. That best-effort failure lifecycle predates the PR; attacker reachability and a materially worsened security outcome were not established.

Hardening Proposals

  • proposed — If malformed-resource recovery or direct parser reuse must preserve complete model guarantees, parse each resource into temporary state and commit only after successful completion. Document whether failed optional model loads discard that resource or fail analysis, rather than allowing partial metadata to become an implicit recovery policy.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.69% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue [#1862] requires annotated JDK fields to be read into the astubx model. The PR extracts top-level JSpecify nullable fields as FieldInfo, writes them in astubx version 2, reads them through `St…
Out of Scope Changes check ✅ Passed The changes remain within issue [#1862]. The astubx version update, version 1 compatibility, cache parsing, library-model integration, test fixtures, and tests directly support serialization and use o…
Title check ✅ Passed The title clearly and concisely describes the main change: reading nullable fields from JSpecify JDK models into astubx.
Description check ✅ Passed The description directly explains the purpose, implementation scope, linked issue, regeneration work, and testing for the changeset.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.68%. Comparing base (630c4d2) to head (2933ff4).

Files with missing lines Patch % Lines
...away/javacplugin/NullnessAnnotationSerializer.java 83.87% 2 Missing and 3 partials ⚠️
...ava/com/uber/nullaway/handlers/StubxCacheUtil.java 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1901      +/-   ##
============================================
+ Coverage     87.67%   87.68%   +0.01%     
- Complexity     3511     3524      +13     
============================================
  Files           110      110              
  Lines         11674    11738      +64     
  Branches       2409     2425      +16     
============================================
+ Hits          10235    10293      +58     
- Misses          659      662       +3     
- Partials        780      783       +3     

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

@msridhar msridhar 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.

Overall this looks really good! Just had a few comments.

Beyond the code comments, I'm wondering if we should separate out the re-generation of jspecify-jdk.astubx and the corresponding test. I've been meaning to update it anyway, as there have been changes on the main branch. I just pushed a new version of my test branch that includes those changes. I'm working on testing out the build now; may need to hack the build script further. I'll comment back when it's ready to go.

@msridhar

msridhar commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

@subhramit I landed updated instructions for generating the astubx file on the master branch

…ndling, cover protected field visibility

Signed-off-by: subhramit <subhramit.bb@live.in>
@msridhar

msridhar commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

@subhramit FYI I now landed #1916 so re-generating the astubx file should be even easier :-)

@subhramit

Copy link
Copy Markdown
Contributor Author

@subhramit FYI I now landed #1916 so re-generating the astubx file should be even easier :-)

Was just working on this - that makes things easier. Thanks.

Signed-off-by: subhramit <subhramit.bb@live.in>
@subhramit

subhramit commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor Author

@msridhar this should now be done - could you go through 688327e and see if I missed anything while addressing?

I also regenerated the astubx using the new script in this PR itself for the sake of completeness (to not add unused functionality to master), but let me know if you'd prefer separating into a follow-up PR.

@msridhar msridhar 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.

Thanks!

@msridhar
msridhar enabled auto-merge (squash) October 4, 2026 21:48
@msridhar
msridhar merged commit 46f47a9 into apache:master Oct 4, 2026
18 of 19 checks passed
@subhramit
subhramit deleted the jdk-models-nullable-fields branch October 4, 2026 22:12
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 19, 2026
The task is registered in every module that applies the test conventions, but two setups leave it blind. Four modules hold tests of nullaway/src/main and no main code of their own, so :nullaway:pitestDiff never runs them and a mutant only they would kill looks alive. The tests of jdk-javac-plugin run the plugin inside javac through -Xplugin, and PIT records no coverage there: against the parent of apache#1901, :jdk-javac-plugin:pitestDiff reported all 14 mutants as not reached by any test, with 0 of 150 lines covered, although its 12 tests ran. CONTRIBUTING.md now names both gaps, and AGENTS.md keeps recommending the task for :nullaway only.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 19, 2026
Gradle moves every -Dname=value given through a Test task's jvmArgs into its systemProperties, and pitestDiff passed only jvmArgs and the heap limit to PIT. A test that reads such a property failed under PIT, and --skipFailingTests dropped it without a word. In jmh, three of the eight tests failed that way, and in jdk-javac-plugin every test did, since all of them read -Dtest.module.path: there, against the parent of apache#1901, all 14 mutants were reported as not reached and 0 of 150 lines as covered. With the properties passed, 10 of those 14 mutants are killed and 143 of 150 lines are covered.

An argument that contains a comma now fails the task, since PIT splits --jvmArgs at commas and would pass it to the test JVM in pieces.

Assisted-by: Claude Code (claude-opus-5-5)
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.

Handle fields in JDK javac plugin

2 participants