Repository navigation
Enable JSpecify JDK models (under a flag) - #1641
Conversation
|
This change is part of the following stack:
Change managed by git-spice. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds the Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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/handlers/LibraryModelsHandler.java`:
- Around line 1681-1692: Rename the bundled resource from output.astubx to
nullaway-jspecify-jdk.astubx and update the JDK model loading block guarded by
isJSpecifyJDKEnabled to use
ExternalStubxLibraryModels.class.getResourceAsStream(...) instead of accessing
getClass().getClassLoader(). Update the missing-resource log, parseStubStream
call, and success log to reference the new resource name.
🪄 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: 74e7363e-d06a-4ecd-982c-2359bca75b98
📒 Files selected for processing (9)
nullaway/build.gradlenullaway/src/main/java/com/uber/nullaway/Config.javanullaway/src/main/java/com/uber/nullaway/DummyOptionsConfig.javanullaway/src/main/java/com/uber/nullaway/ErrorBuilder.javanullaway/src/main/java/com/uber/nullaway/ErrorProneCLIFlagsConfig.javanullaway/src/main/java/com/uber/nullaway/LibraryModels.javanullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.javanullaway/src/main/resources/output.astubxnullaway/src/test/java/com/uber/nullaway/JSpecifyJDKModelsTest.java
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1641 +/- ##
============================================
- Coverage 88.20% 88.16% -0.04%
- Complexity 3060 3065 +5
============================================
Files 105 105
Lines 10282 10302 +20
Branches 2074 2079 +5
============================================
+ Hits 9069 9083 +14
- Misses 572 576 +4
- Partials 641 643 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| if (stubxInputStream == null) { | ||
| throw new RuntimeException("could not get input stream for " + astubxPath); | ||
| } |
There was a problem hiding this comment.
This change is due to the new JDK models (which model the return of getResourceAsStream as @Nullable)
| Matcher matcher = METHOD_SIG_PATTERN.matcher(methodSignature); | ||
| if (matcher.find()) { | ||
| String methodName = matcher.group(2); | ||
| String methodName = castToNonNull(matcher.group(2)); |
There was a problem hiding this comment.
This change is due to the new JDK models (which model the return of Matcher.group as @Nullable)
| ImmutableMap<MethodRef, ImmutableSetMultimap<Integer, NestedAnnotationInfo>> refs) { | ||
| return makeOptimizedLookup( | ||
| names, refs.keySet(), ref -> NullabilityUtil.castToNonNull(refs.get(ref))); | ||
| return makeOptimizedLookup(names, refs.keySet(), ref -> castToNonNull(refs.get(ref))); |
There was a problem hiding this comment.
This change is due to the new static import
|
@coderabbitai review |
✅ Action performedReview finished.
|
439fe21 to
d220b1a
Compare
12d4d1b to
5b7d5bc
Compare
a1a802f to
0f1d1b0
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
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/StubxCacheUtil.java (1)
130-139: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winClose provider resource streams.
parseStubStream()does not closestubxInputStream; wrap the stream acquisition and parsing in try-with-resources to avoid retaining provider JAR resources.Proposed fix
- InputStream stubxInputStream = providerClass.getResourceAsStream(astubxPath); - if (stubxInputStream == null) { - throw new RuntimeException("could not get input stream for " + astubxPath); - } String stubxLocation = providerClass + ":" + astubxPath; - try { + try (InputStream stubxInputStream = providerClass.getResourceAsStream(astubxPath)) { + if (stubxInputStream == null) { + throw new RuntimeException("could not get input stream for " + astubxPath); + } parseStubStream(stubxInputStream, stubxLocation); LOG(DEBUG, "DEBUG", "loaded stubx file " + stubxLocation); } catch (IOException e) {🤖 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/StubxCacheUtil.java` around lines 130 - 139, Update the stubx stream handling around providerClass.getResourceAsStream and parseStubStream in StubxCacheUtil to use try-with-resources, ensuring stubxInputStream is closed after parsing while preserving the existing null check, logging, and RuntimeException 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/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java`:
- Around line 1680-1694: Update the missing-resource branch in the JSpecify JDK
model loading block to throw an exception naming JSPECIFY_JDK_ASTUBX_FILENAME
instead of only calling astubxLoadLog. Preserve the existing parsing and
successful-load behavior when the resource is present.
- Around line 1658-1660: Update ExternalStubxLibraryModels so constructing
StubxCacheUtil does not eagerly discover JarInfer providers. Separate provider
discovery from cache construction, and perform the discovery only when
isJarInferEnabled is true, preserving JSpecify-only runs without external
JarInfer models.
In `@nullaway/src/test/java/com/uber/nullaway/JSpecifyJDKModelsTest.java`:
- Around line 14-32: Update modelsDisabledDoesNotLoadAstubxModel to construct
its CompilationTestHelper with JSpecifyJavacConfig.withJSpecifyModeArgs(...),
while omitting JSpecifyJDKModels from the configured models. Preserve the
existing AnnotatedPackages=foo setup and Attributes.get() assertion so the test
specifically exercises the disabled JDK-model path in JSpecify mode.
---
Outside diff comments:
In `@nullaway/src/main/java/com/uber/nullaway/handlers/StubxCacheUtil.java`:
- Around line 130-139: Update the stubx stream handling around
providerClass.getResourceAsStream and parseStubStream in StubxCacheUtil to use
try-with-resources, ensuring stubxInputStream is closed after parsing while
preserving the existing null check, logging, and RuntimeException 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: 8f065239-1a9f-42c5-be6c-70b404bc5b19
📒 Files selected for processing (11)
jdk-javac-plugin/README.mdnullaway/build.gradlenullaway/src/main/java/com/uber/nullaway/Config.javanullaway/src/main/java/com/uber/nullaway/DummyOptionsConfig.javanullaway/src/main/java/com/uber/nullaway/ErrorProneCLIFlagsConfig.javanullaway/src/main/java/com/uber/nullaway/LibraryModels.javanullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.javanullaway/src/main/java/com/uber/nullaway/handlers/StubxCacheUtil.javanullaway/src/main/resources/jspecify-jdk.astubxnullaway/src/test/java/com/uber/nullaway/ErrorProneCLIFlagsConfigTest.javanullaway/src/test/java/com/uber/nullaway/JSpecifyJDKModelsTest.java
There was a problem hiding this comment.
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 `@jdk-javac-plugin/README.md`:
- Around line 22-37: Update the README code block around the shell commands to
include blank lines before and after the fence, declare the fence language as
bash, and ensure the file ends with exactly one newline.
🪄 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: 2ee54848-0cfb-4498-b571-e7004bcbc0e3
📒 Files selected for processing (11)
jdk-javac-plugin/README.mdnullaway/build.gradlenullaway/src/main/java/com/uber/nullaway/Config.javanullaway/src/main/java/com/uber/nullaway/DummyOptionsConfig.javanullaway/src/main/java/com/uber/nullaway/ErrorProneCLIFlagsConfig.javanullaway/src/main/java/com/uber/nullaway/LibraryModels.javanullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.javanullaway/src/main/java/com/uber/nullaway/handlers/StubxCacheUtil.javanullaway/src/main/resources/jspecify-jdk.astubxnullaway/src/test/java/com/uber/nullaway/ErrorProneCLIFlagsConfigTest.javanullaway/src/test/java/com/uber/nullaway/JSpecifyJDKModelsTest.java
There was a problem hiding this comment.
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)
1658-1660: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftDo not eagerly discover JarInfer models in JSpecify-only mode.
Constructing
StubxCacheUtilinvokesloadStubxFiles()from its constructor (Line 97 ofnullaway/src/main/java/com/uber/nullaway/handlers/StubxCacheUtil.java). Therefore,isJarInferEnabled=falseandisJSpecifyJDKEnabled=truestill discovers and parses JarInfer providers, violating the two flags’ independence and potentially failing on unrelated JarInfer resources.Split cache construction from JarInfer provider discovery, or pass the JarInfer flag into
StubxCacheUtiland load providers only when it is enabled.🤖 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 1658 - 1660, Update ExternalStubxLibraryModels so StubxCacheUtil does not eagerly discover or parse JarInfer providers when isJarInferEnabled is false, including JSpecify-only mode. Split cache construction from provider discovery or pass the JarInfer flag into StubxCacheUtil and conditionally load providers only when enabled, while preserving JSpecify model 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.
Outside diff comments:
In `@nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java`:
- Around line 1658-1660: Update ExternalStubxLibraryModels so StubxCacheUtil
does not eagerly discover or parse JarInfer providers when isJarInferEnabled is
false, including JSpecify-only mode. Split cache construction from provider
discovery or pass the JarInfer flag into StubxCacheUtil and conditionally load
providers only when enabled, while preserving JSpecify model handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 756a3459-91ab-4b0c-b4c8-1bed3f780fa6
📒 Files selected for processing (2)
nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.javanullaway/src/main/java/com/uber/nullaway/handlers/StubxCacheUtil.java
…DK models (apache#2028) Four behaviors fixed by earlier changes had no test, so a regression in any of them would pass the suite. - apache#848: when `AnnotatedPackages` matches `java.lang` (the report used `[a-zA-Z0-9.]*`), an enum constructor's implicit `super()` resolves to `Enum(String, int)` with no arguments, and NullAway failed with `java.lang.IndexOutOfBoundsException` in `handleInvocation`. apache#1284 fixed it by iterating over the actual arguments. The new `CoreTests` case fails with that exception on dd0da6d, the parent of apache#1284. - apache#1027: `VarargsTests.testVarargsRestrictive` and `JSpecifyVarargsTests.testVarargsRestrictive` declared callees with a type-use `@NonNull` on both the elements and the array, and with a `@NonNull` that is both a declaration and a type-use annotation on the array, the elements, or both, but never called them. Both tests now call each one, and the JSpecify test loses its "WIP" comment. - apache#1236: with the JSpecify JDK models (apache#1641), a `@Nullable` key or value passed to `Map.of`, or a `@Nullable` element passed to `List.of`, is reported. No test covered the factories. Without the models, as in the reporter's setup with JSpecify mode off, these calls are still not reported. - apache#672: with the JSpecify JDK models, an `equals(Object)` override whose parameter is not `@Nullable` is reported, and one with `@Nullable` is not. apache#672 stays open, because whether default mode should report it too is a maintainer decision. The last paragraph of apache#1027 expects restrictive annotations in `@NullUnmarked` code to be read without `AcknowledgeRestrictiveAnnotations`. That holds in JSpecify mode only; standard mode ignores them, as `NullMarkednessTests.methodRefToNullUnmarkedNoAcknowledgeRestrictive` asserts, and this change keeps that. Only the apache#848 case was run red on a pre-fix commit; the other cases record behavior already on master. Fixes apache#848 Fixes apache#1027 Fixes apache#1236 Assisted-by: Claude Code (claude-opus-5-5) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Tests** * Expanded coverage for nullable enum constructor parameters when package annotations match broadly. * Added checks for nullable arguments passed to JDK collection factory methods and for nullability requirements on `equals` overrides. * Added varargs cases covering nullable arrays and elements with JSpecify and custom nullability annotations. These tests verify that nullable arguments in restrictive scenarios produce diagnostics. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…odels (apache#2033) With `WarnOnGenericInferenceFailure` on and no JDK models, returning `Objects.requireNonNullElse(nullable, nonNull)` from a method with a non-null `String` return reports `inference failure: type variable T constrained to be both @nonnull and @Nullable` (apache#1493). The JSpecify JDK models (apache#1641, NullAway 0.14.0) declare `<T> T requireNonNullElse(@nullable T obj, @nullable T defaultObj)`, so `T` is inferred as non-null `String` and nothing is reported. The models are enabled by `-XepOpt:NullAway:JSpecifyJDKModels=true`, or by `-XepOpt:NullAway:JSpecifyExperimental=true`, whose value that flag defaults to. `GenericMethodTests.issue1493` was added with `@Ignore` in apache#1496 and passes now. This change enables it as `issue1493RequireNonNullElseWithJdkModels` and adds `issue1493RequireNonNullElseWithoutJdkModels`, which compiles the same source with `JSpecifyJDKModels=false` and expects the inference failure. Both tests set `WarnOnGenericInferenceFailure=true` and `JSpecifyJDKModels` explicitly instead of taking them from the `JSpecifyExperimental` default, so the pair differs only in the models flag; with that flag set to `true`, the second test fails with "There were no errors". Refs apache#1493. Merging does not close it: the reporter's configuration without the models (`JSpecifyMode` plus `WarnOnGenericInferenceFailure=true`) still reports the warning, and whether the issue can close before the models are on by default is for the maintainers to decide. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Tests** * Added enabled coverage for `Objects.requireNonNullElse` generic inference with JSpecify JDK models enabled and disabled. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This PR adds an astubx capturing JSpecify JDK models of nullability, and loads and uses those models when a flag is enabled. We enable the flag for checking NullAway itself. The new JDK models can only be used in JSpecify mode, since JSpecify-mode checking is required to not get a lot of false positive warnings.
We also add a basic document on how to run our code to generate the astubx file.
For now, we add a separate flag for loading JDK models from the JarInfer flag. We can consider merging these flags in a follow-up if desirable.
Some changes in this PR fix new NullAway warnings that are due to the new models. I could try to split out those changes into a separate PR, but they're pretty localized so I just decided to do them here.
This PR was originally authored by @haewiful
Summary by CodeRabbit
.astubxartifact.