Option that loads nullness information of JDK package#1472
Option that loads nullness information of JDK package#1472haewiful wants to merge 8 commits intouber:masterfrom
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. 💤 Files selected but had no reviewable changes (1)
You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughAdds a new JDK inference configuration flag and wiring throughout the codebase. Introduces Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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: 2
🤖 Fix all issues with AI agents
In `@nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java`:
- Line 1564: The constructor ExternalStubxLibraryModels(boolean
isJarInferEnabled, boolean isJDKInferEnabled) uses two positional booleans that
are easy to swap; change the API to accept a descriptive config object or
factory so callers pass named fields. Create a small value class (e.g.,
LibraryInferOptions or InferConfig) with boolean fields jarInferEnabled and
jdkInferEnabled, update ExternalStubxLibraryModels to take that single config
parameter, and update the existing call site to construct and pass the config
(or alternatively add clearly named static factory methods on
ExternalStubxLibraryModels like createWith(jarEnabled, jdkEnabled)). Ensure the
constructor and any usages are updated consistently.
- Around line 1588-1600: Fix the typo in the comment inside LibraryModelsHandler
near the JDK astubx loading block: change "infered" to "inferred" in the comment
that references hardcoded loading of stubx files when isJDKInferEnabled (the
block using getClass().getClassLoader().getResourceAsStream("output.astubx") and
cacheUtil.parseStubStream). Do not change resource names or logic—only update
the comment wording.
| private final Map<String, SetMultimap<Integer, NestedAnnotationInfo>> nestedAnnotationInfo; | ||
|
|
||
| ExternalStubxLibraryModels() { | ||
| ExternalStubxLibraryModels(boolean isJarInferEnabled, boolean isJDKInferEnabled) { |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Constructor now accepts two separate booleans — consider clarity.
Two positional boolean parameters (isJarInferEnabled, isJDKInferEnabled) can be accidentally swapped at call sites without a compiler error. This is a minor readability concern for now since there's only one call site (Line 483), but worth noting.
🤖 Prompt for AI Agents
In `@nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java`
at line 1564, The constructor ExternalStubxLibraryModels(boolean
isJarInferEnabled, boolean isJDKInferEnabled) uses two positional booleans that
are easy to swap; change the API to accept a descriptive config object or
factory so callers pass named fields. Create a small value class (e.g.,
LibraryInferOptions or InferConfig) with boolean fields jarInferEnabled and
jdkInferEnabled, update ExternalStubxLibraryModels to take that single config
parameter, and update the existing call site to construct and pass the config
(or alternatively add clearly named static factory methods on
ExternalStubxLibraryModels like createWith(jarEnabled, jdkEnabled)). Ensure the
constructor and any usages are updated consistently.
nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java
Outdated
Show resolved
Hide resolved
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 (2)
nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java (2)
568-586:⚠️ Potential issue | 🟡 MinorWrap the Android
InputStreamin try-with-resources to prevent resource leaks.The
InputStreamobtained from the Android model class loader at line 1570 is never closed. AlthoughparseStubStreamdoes not close the stream internally, the JDK loading pattern at line 1590 correctly uses try-with-resources. Apply the same pattern to the Android code for consistency and to prevent the stream from leaking ifparseStubStreamthrows an exception.Proposed fix
if (isJarInferEnabled) { try { - InputStream androidStubxIS = - Class.forName(ANDROID_MODEL_CLASS) - .getClassLoader() - .getResourceAsStream(ANDROID_ASTUBX_LOCATION); - if (androidStubxIS != null) { - cacheUtil.parseStubStream(androidStubxIS, "android.jar: " + ANDROID_ASTUBX_LOCATION); - astubxLoadLog("Loaded Android RT models."); + try (InputStream androidStubxIS = + Class.forName(ANDROID_MODEL_CLASS) + .getClassLoader() + .getResourceAsStream(ANDROID_ASTUBX_LOCATION)) { + if (androidStubxIS != null) { + cacheUtil.parseStubStream(androidStubxIS, "android.jar: " + ANDROID_ASTUBX_LOCATION); + astubxLoadLog("Loaded Android RT models."); + } } } catch (ClassNotFoundException e) {
588-600:⚠️ Potential issue | 🟠 MajorGeneric resource name
output.astubxrisks classpath collisions.The resource name
"output.astubx"is not namespaced, so any other JAR on the classpath with the same resource name could shadow or be loaded instead of the intended JDK nullness data. Consider using a more specific name (e.g.,"com/uber/nullaway/jdk-nullness.astubx") to avoid ambiguity.The loading logic itself (try-with-resources, null check, exception handling) is well-structured.
#!/bin/bash # Check how/where output.astubx is generated and placed echo "=== Searching for output.astubx references ===" rg -n "output\.astubx" --type-not class -C 2 echo "" echo "=== Checking resource directories ===" fd "output.astubx" --type f echo "" echo "=== Checking build configs for resource placement ===" rg -n "output\.astubx" -g "*.gradle*" -g "*.xml" -C 3
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1472 +/- ##
============================================
- Coverage 88.46% 88.42% -0.04%
- Complexity 2757 2760 +3
============================================
Files 99 99
Lines 9196 9210 +14
Branches 1847 1850 +3
============================================
+ Hits 8135 8144 +9
- Misses 521 526 +5
Partials 540 540 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This pull request adds some nullness check support for modules in the JDK package.
NullAway:JDKInferEnabledthat lets the users decide whether to load the astubx file to NullAway.Some related PRs are #1333.
The unit tests that are added to
LibraryModelsHandlerTest.javafile.Summary by CodeRabbit
New Features
Bug Fixes / Behavior
Tests