Skip to content

Read the JSpecify JDK models from the jspecify-jdk-stubs jar - #2162

Draft
vlsi wants to merge 1 commit into
apache:masterfrom
vlsi:claude/class-annotation-reader-62ddab
Draft

vlsi wants to merge 1 commit into
apache:masterfrom
vlsi:claude/class-annotation-reader-62ddab

Conversation

@vlsi

@vlsi vlsi commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

NullAway bundled the JSpecify JDK models as jspecify-jdk.astubx, which regenerate-jspecify-jdk.sh produced by building the annotated JSpecify JDK with a javac plugin and converting the result. Updating the models meant rerunning that pipeline by hand and committing a 325 KB binary file.

The build now downloads the jspecify-jdk-stubs jar for JDK 28 early access (a GitHub release asset of vlsi/jspecify-jdk-stubs, version jspecifyJdkStubs in gradle/libs.versions.toml) and packs it into the NullAway jar as jspecify-jdk-stubs.jar, with its entries repacked uncompressed. The NullAway jar then compresses the class files as one stream, which is smaller and inflates faster than ~850 entries compressed one by one. JSpecifyJdkStubsReader reads its class files when the models load and fills the same StubxCacheUtil caches, with the keys the astubx file used: methods as javac's MethodSymbol.toString() renders them, fields by flat class name, classes by dotted name. It reads only the constant pool, signatures, InnerClasses, and the JSpecify annotations, and skips method bodies. A class-file library such as ASM would have to be shaded into NullAway for that. Renovate updates jspecifyJdkStubs through a github-releases custom manager; the jdk28-ea classifier is changed by hand.

User-visible:
A top-level @NonNull on a JDK method parameter is modeled as a non-null parameter, for example the value parameter of Map.merge.
java.nio.ByteBuffer is @NullMarked, as the stubs declare it.
Non-public JDK members, such as sun.swing.DefaultLookup, are no longer modeled.
The NullAway jar grows by about 220 KB: the stubs jar takes 277 KB in it, where the astubx file took about 54 KB.
Not changed:
@NullUnmarked in the stubs is not modeled; astubx has no slot for it.
An annotation on an enclosing type of an inner class, as in Outer<@Nullable String>.Inner, is skipped, as the astubx generator skipped it.

Scope. The build verifies no checksum of the downloaded jar, and a GitHub release asset can be replaced under the same tag, unlike a Maven Central artifact. Pinning a SHA-256 would stop Renovate from updating the version on its own; publishing the stubs to Maven Central would avoid both. That choice is left to the maintainers.

See #2160.

Assisted-by: Claude Code (claude-opus-5-5)

🤖 Generated with Claude Code

@vlsi
vlsi force-pushed the claude/class-annotation-reader-62ddab branch from 7dfea38 to 373a392 Compare November 14, 2026 14:19
@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.32624% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.61%. Comparing base (009d7cb) to head (f53e126).

Files with missing lines Patch % Lines
...uber/nullaway/handlers/JSpecifyJdkStubsReader.java 94.37% 8 Missing and 15 partials ⚠️
...m/uber/nullaway/handlers/LibraryModelsHandler.java 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2162      +/-   ##
============================================
+ Coverage     89.44%   89.61%   +0.17%     
- Complexity     4009     4128     +119     
============================================
  Files           113      114       +1     
  Lines         13148    13567     +419     
  Branches       2723     2819      +96     
============================================
+ Hits          11760    12158     +398     
- Misses          624      632       +8     
- Partials        764      777      +13     

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

NullAway bundled the JSpecify JDK models as jspecify-jdk.astubx, which
regenerate-jspecify-jdk.sh produced by building the annotated JSpecify JDK
with a javac plugin and converting the result. Updating the models meant
rerunning that pipeline by hand and committing a 325 KB binary file.

The build now downloads the jspecify-jdk-stubs jar for JDK 28 early access
(a GitHub release asset of vlsi/jspecify-jdk-stubs, version jspecifyJdkStubs
in gradle/libs.versions.toml) and packs it into the NullAway jar as
jspecify-jdk-stubs.jar, with its entries repacked uncompressed. The NullAway
jar then compresses the class files as one stream, which is smaller and
inflates faster than ~850 entries compressed one by one. JSpecifyJdkStubsReader reads its class files when
the models load and fills the same StubxCacheUtil caches, with the keys the
astubx file used: methods as javac's MethodSymbol.toString() renders them,
fields by flat class name, classes by dotted name. It reads only the
constant pool, signatures, InnerClasses, and the JSpecify annotations, and
skips method bodies. A class-file library such as ASM would have to be
shaded into NullAway for that. Renovate updates jspecifyJdkStubs through a
github-releases custom manager; the jdk28-ea classifier is changed by hand.

User-visible:
A top-level @nonnull on a JDK method parameter is modeled as a non-null parameter, for example the value parameter of Map.merge.
java.nio.ByteBuffer is @NullMarked, as the stubs declare it.
Non-public JDK members, such as sun.swing.DefaultLookup, are no longer modeled.
The NullAway jar grows by about 220 KB: the stubs jar takes 277 KB in it, where the astubx file took about 54 KB.
Not changed:
@NullUnmarked in the stubs is not modeled; astubx has no slot for it.
An annotation on an enclosing type of an inner class, as in Outer<@nullable String>.Inner, is skipped, as the astubx generator skipped it.

See apache#2160.

Assisted-by: Claude Code (claude-opus-5-5)
@vlsi
vlsi force-pushed the claude/class-annotation-reader-62ddab branch from 373a392 to f53e126 Compare November 14, 2026 14:35
@vlsi

vlsi commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Load time and size of the JDK models

NullAway loads the JDK models once, when LibraryModelsHandler is created. With this PR, the first load takes about 10 ms more CPU than reading the astubx file on master, and a load on a warm JVM about 8 ms more. nullaway.jar grows by about 220 KB.

Measurements

Each figure is the CPU time of the loading thread, from the resource stream to the filled StubxCacheUtil caches: JSpecifyJdkStubsReader.read for this PR, and StubxCacheUtil.parseStubStream on jspecify-jdk.astubx for master. Both resources are read as deflated entries of nullaway.jar, the way getResourceAsStream returns them. JDK 21, Apple M1 Max, commit f53e126.

Cold JVM, first load (9 runs) Warm JVM, median of ~2000 runs Resource in nullaway.jar
master: jspecify-jdk.astubx 47–54 ms 1.4 ms 54 KB
this PR: jspecify-jdk-stubs.jar 59–66 ms 9.1 ms 277 KB

The cold figures also include loading Guava and the NullAway classes both versions use, so only the difference between the rows belongs to the reader.

Why the build repacks the stubs jar

The release asset compresses each of its ~850 class files separately. The build repacks it with uncompressed entries, and nullaway.jar compresses the whole jar as one entry. Compressed together, the class files share their repeated constant pool strings, so the resource takes 277 KB in nullaway.jar instead of 516 KB. Loading also gets faster: one stream is inflated instead of a jar inside a jar, and the warm load drops from 14.6 ms to 9.1 ms.

Where the 9.1 ms go

From a CPU profile (async-profiler) of the warm load:

Share Time What
46% 4.2 ms inflating the 1.37 MB resource out of nullaway.jar
22% 2.0 ms parsing signatures and rendering method keys in the format the astubx caches use, MethodSymbol.toString() of javac
9% 0.8 ms filling the StubxCacheUtil caches, which master pays too
6% 0.6 ms copying each class file out of the zip stream
17% 1.5 ms the rest of class-file reading: constant pool, attributes, type annotations

Possible follow-ups

  • Key the JDK models by owner, name, and descriptor instead of the rendered signature. This removes most of the 2.0 ms of key rendering, but the lookup side would have to build the same key from a MethodSymbol. LibraryModels.MethodRef is public API keyed by strings, so the JDK models would need a map of their own.
  • Store the resource uncompressed in nullaway.jar. This removes the 4.2 ms of inflating, but nullaway.jar grows by about 1.1 MB, and Gradle's Jar task sets one compression method for the whole archive.

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.

1 participant