Skip to content

Enable JSpecify JDK models for regression tests - #1646

Merged
msridhar merged 8 commits into
masterfrom
use-jdk-models-on-unit-tests
Jul 24, 2026
Merged

Enable JSpecify JDK models for regression tests#1646
msridhar merged 8 commits into
masterfrom
use-jdk-models-on-unit-tests

Conversation

@msridhar

@msridhar msridhar commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

This PR enables the JSpecify JDK models for all regression tests run in JSpecify mode.

The change exposed a bug where enabling the JDK models also enabled loading of external astubx files. We fix that here and only load external astubx files if JarInfer is enabled.

There were a couple of issues exposed by this change by our current tests. One is documented in #1616. Another is fixed in #1647, a follow-up to this PR. Another is just a change in the warning that gets printed.

Summary by CodeRabbit

  • New Features
    • Added a new compiler option to enable JSpecify JDK model support (-XepOpt:NullAway:JSpecifyJDKModels=true).
  • Bug Fixes
    • Improved how JSpecify-related compiler arguments are composed and processed when JSpecify mode is enabled.
    • Updated stubx model caching to only load stubx files when JarInfer-based model loading is enabled.
  • Tests
    • Adjusted JSpecify JDK models test configurations and updated expected nullability/diagnostic outcomes for generics, conditional expressions, and stream filtering.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.16%. Comparing base (b9d7871) to head (90a73c0).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1646   +/-   ##
=========================================
  Coverage     88.16%   88.16%           
- Complexity     3065     3066    +1     
=========================================
  Files           105      105           
  Lines         10302    10303    +1     
  Branches       2079     2080    +1     
=========================================
+ Hits           9083     9084    +1     
  Misses          576      576           
  Partials        643      643           

☔ 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 force-pushed the use-jdk-models-on-unit-tests branch from f056a9a to 0156e31 Compare July 23, 2026 04:57
@msridhar
msridhar force-pushed the use-jdk-models-on-unit-tests branch 2 times, most recently from bd65c72 to 69e379d Compare July 24, 2026 00:32
@msridhar
msridhar requested a review from lazaroclapp July 24, 2026 00:35
@msridhar
msridhar marked this pull request as ready for review July 24, 2026 00:35
static class K<T extends @Nullable Object> {}
void foo(K<@Nullable Object> k) {
K<? extends @Nullable Object> k2 = k;
// TODO should get no error here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is fixed by #1647

"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber"))
JSpecifyJavacConfig.withJSpecifyModeArgs(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Run this one in JSpecify mode to ensure that loading of JDK models does not also load external astubx files from JarInfer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Might be worth putting this comment into the code itself?

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@msridhar, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 3 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c0265228-c8c0-4a14-b05d-6b8de0e117de

📥 Commits

Reviewing files that changed from the base of the PR and between 224af39 and 90a73c0.

📒 Files selected for processing (2)
  • jdk-annotations/jdk-integration-test/src/test/java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.java
  • nullaway/src/test/java/com/uber/nullaway/JSpecifyJDKModelsTest.java

Walkthrough

Adds the JSpecifyJDKModels compiler flag to JSpecify mode configuration and conditionally loads stubx models based on JarInfer enablement. Updates integration and JSpecify model tests to distinguish enabled and disabled configurations, and revises expected nullability diagnostics.

Possibly related issues

Possibly related PRs

  • uber/NullAway#1641 — Shares the JSpecify JDK models flag and model-loading path.
  • uber/NullAway#1648 — Adds handling that enables the same underlying JSpecify JDK models behavior.
  • uber/NullAway#1649 — Also changes JSpecify mode flag composition in JSpecifyJavacConfig.

Suggested reviewers: yuxincs, lazaroclapp

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: enabling JSpecify JDK models in regression tests.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch use-jdk-models-on-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.

@lazaroclapp lazaroclapp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

SGTM, modulo the follow ups

"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber"))
JSpecifyJavacConfig.withJSpecifyModeArgs(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Might be worth putting this comment into the code itself?

Comment thread nullaway/src/test/java/com/uber/nullaway/JSpecifyJDKModelsTest.java Outdated
@msridhar
msridhar force-pushed the use-jdk-models-on-unit-tests branch from 62af508 to 0b639da Compare July 24, 2026 04:02

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java (1)

1680-1694: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Fail fast when the JSpecify JDK model is missing.

With JSpecify JDK models enabled, a missing jspecify-jdk.astubx resource goes to a no-op debug log, so NullAway continues without the JDK nullability models and can miss reports such as those covered by JSpecifyJDKModelsTest. Treat the missing required resource as a normal warning/error.

🤖 Prompt for 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.

In `@nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java`
around lines 1680 - 1694, The JSpecify JDK model loading branch must not
silently continue when JSPECIFY_JDK_ASTUBX_FILENAME is absent. Update the
null-resource handling in the isJSpecifyJDKEnabled block to emit a normal
warning or error and fail fast, while preserving successful parsing and existing
IOException handling.
🤖 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/test/java/com/uber/nullaway/jspecify/GenericsTests.java`:
- Around line 2008-2010: Update the local variable declaration for o in the
toArray() test to remove the top-level `@Nullable` annotation and express nullable
array-reference semantics as Object `@Nullable` [] (or rely on var/inferred typing
if appropriate). Preserve the ternary behavior and existing toArray() model
TODO.

---

Outside diff comments:
In `@nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java`:
- Around line 1680-1694: The JSpecify JDK model loading branch must not silently
continue when JSPECIFY_JDK_ASTUBX_FILENAME is absent. Update the null-resource
handling in the isJSpecifyJDKEnabled block to emit a normal warning or error and
fail fast, while preserving successful parsing and existing IOException
handling.
🪄 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 Plus

Run ID: 81ae1b3e-5898-48b4-8a27-d2073113196d

📥 Commits

Reviewing files that changed from the base of the PR and between 62af508 and 0b639da.

📒 Files selected for processing (7)
  • jdk-annotations/jdk-integration-test/src/test/java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.java
  • nullaway/src/main/java/com/uber/nullaway/generics/JSpecifyJavacConfig.java
  • nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java
  • nullaway/src/main/java/com/uber/nullaway/handlers/StubxCacheUtil.java
  • nullaway/src/test/java/com/uber/nullaway/JSpecifyJDKModelsTest.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/StreamNullabilityPropagatorTests.java

Base automatically changed from jdk-astubx to master July 24, 2026 04:26
@msridhar
msridhar force-pushed the use-jdk-models-on-unit-tests branch from 0b639da to 224af39 Compare July 24, 2026 04:28
msridhar and others added 2 commits July 23, 2026 21:30
@msridhar
msridhar enabled auto-merge (squash) July 24, 2026 04:32

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

♻️ Duplicate comments (1)
nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java (1)

2008-2010: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Annotate the nullable array reference, not its component type.

@Nullable Object[] makes the component type nullable, so o is still a non-null array, while the false branch is null. Use Object @nullable [] o for the intended ternary result.

Based on learnings, Nullable Object[] annotates the component type, whereas Object @nullable [] annotates the array reference.

Proposed fix
-               `@Nullable` Object[] o = a != null ? a.toArray() : null;
+               Object `@Nullable` [] o = a != null ? a.toArray() : null;
🤖 Prompt for 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.

In `@nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java` around
lines 2008 - 2010, Update the declaration of variable o in the toArray() ternary
to annotate the array reference rather than its component type, using the
project’s array-annotation syntax so the nullable false branch is accepted.

Source: Learnings

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

Duplicate comments:
In `@nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java`:
- Around line 2008-2010: Update the declaration of variable o in the toArray()
ternary to annotate the array reference rather than its component type, using
the project’s array-annotation syntax so the nullable false branch is accepted.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2a264c52-32a1-4c05-a16d-467f26da245f

📥 Commits

Reviewing files that changed from the base of the PR and between 0b639da and 224af39.

📒 Files selected for processing (7)
  • jdk-annotations/jdk-integration-test/src/test/java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.java
  • nullaway/src/main/java/com/uber/nullaway/generics/JSpecifyJavacConfig.java
  • nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java
  • nullaway/src/main/java/com/uber/nullaway/handlers/StubxCacheUtil.java
  • nullaway/src/test/java/com/uber/nullaway/JSpecifyJDKModelsTest.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/StreamNullabilityPropagatorTests.java

@msridhar
msridhar merged commit 6943dea into master Jul 24, 2026
14 checks passed
@msridhar
msridhar deleted the use-jdk-models-on-unit-tests branch July 24, 2026 05:12
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.

2 participants