Skip to content

Updating the JSpecify JDK models requires building a JDK #2160

Open

Description

@vlsi

Updating nullaway/src/main/resources/jspecify-jdk.astubx takes a full JDK build. jdk-javac-plugin/regenerate-jspecify-jdk.sh fetches jspecify/jdk at the commit pinned in the script, runs configure and make jdk with the NullnessAnnotationSerializer javac plugin hooked into the build, converts the JSON it writes with astubx-generator-cli, and copies the result into the source tree, where it is committed (288 KB). No CI workflow runs the script, so the model is as old as the last manual run (#1901), and Renovate cannot propose an update because the jspecify/jdk commit is pinned in a shell variable.

I publish the same annotations as prebuilt jars in vlsi/jspecify-jdk-stubs. Each monthly release has one jar per Java SE release, holding header-only class files of every JDK class that carries a JSpecify annotation, with the API that javac --release <N> sees. v2026.11.13 has jars for 8, 11, 17, 21, 25, 26, and 27, plus jspecify-jdk-stubs-jdk28-ea.jar, whose API comes from the early-access build JDK 28.0.0+24.0.ea. The release workflow compiles code that calls the JDK with NullAway against each jar before it publishes it.

I'd like updating the JDK models to be a dependency version bump that Renovate opens and CI verifies, with no JDK checkout and no JDK build. I see two ways to get there, and which one fits NullAway is your call:

  1. Keep .astubx, and generate it during the NullAway build from a jspecify-jdk-stubs jar, for example the newest one. The converter would read annotations from class files instead of the JSON the javac plugin writes today. The .astubx becomes a build output, so it no longer lives in git, and jdk-javac-plugin and the regeneration script can go.
  2. Deprecate .astubx for the JDK, and have NullAway open a jspecify-jdk-stubs jar as a resource and read the annotations from its class files. Users get the models with no extra flags, as they do now with -XepOpt:NullAway:JSpecifyJDKModels=true. Since each Java SE release has its own jar, NullAway could also pick the one that matches --release, and the early-access jar for a release newer than the newest GA one, where the .astubx holds one model for all releases. I have not prototyped this.

The jspecify-jdk-stubs README describes putting a jar in front of the platform classes with --patch-module java.base=..., and NullAway already reads the annotations from it. That is not what I propose here: every user would have to configure it, it covers java.base only, and it needs -XDaddTypeAnnotationsToSymbol=true, which javac of JDK 21 accepts only from 21.0.8.

I compared the current jspecify-jdk.astubx (jspecify/jdk e89cf6d) with the jdk27 and jdk28-ea jars of v2026.11.13 (jspecify/jdk 97c11a7, ten commits later, which only add @Nullable). I covered null-marked classes, return and parameter nullness, nested nullness in type arguments, arrays, and wildcards, nullable type-parameter bounds, and nullable fields. Every .astubx entry for a class or member in the release-27 API is in the jdk27 jar with the same annotation. The jdk28-ea jar also has the JDK 28 methods the .astubx models, such as Objects.hasIdentity and Objects.requireIdentity. What neither jar has is internal or package-private classes and members (for example sun.swing.DefaultLookup, Component.getParent_NoClientCode()), and Objects.equals(String, String), which jspecify/jdk declares as "an overload that is unique to j2cl" and no JDK has.

The jar also carries what the .astubx format has no slot for. For example, eight methods are @NullUnmarked in jspecify/jdk, among them HttpCookie.getValue() and Files.getAttribute. AstubxGenerator drops that annotation, so in the .astubx these methods look null-marked. Top-level @NonNull, as in Map.merge(K, @NonNull V, ...), is missing from the .astubx as well. Option 2 would also retire AstubxGenerator for the JDK, and with it #2159.

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

Activity

  1. msridhar commented on Nov 13, 2026

    @msridhar
    Contributor

    Very cool! I'm generally in favor of more automation here and this looks promising.

    1. Keep .astubx, and generate it during the NullAway build from a jspecify-jdk-stubs jar, for example the newest one. The converter would read annotations from class files instead of the JSON the javac plugin writes today. The .astubx becomes a build output, so it no longer lives in git, and jdk-javac-plugin and the regeneration script can go.
    2. Deprecate .astubx for the JDK, and have NullAway open a jspecify-jdk-stubs jar as a resource and read the annotations from its class files. Users get the models with no extra flags, as they do now with -XepOpt:NullAway:JSpecifyJDKModels=true. Since each Java SE release has its own jar, NullAway could also pick the one that matches --release, and the early-access jar for a release newer than the newest GA one, where the .astubx holds one model for all releases. I have not prototyped this.

    Do you think 1 will be more efficient? I guess we'd have to prototype to test it, but my feeling is reading in a specialized binary format on each NullAway run will be faster than parsing annotations from class files. On the other hand, class files are also binaries, and these are stubs, so maybe there won't be much difference.

    For 2 we'd either need to introduce a dependence from NullAway to ASM or some other class-reading library (we cannot rely on ClassFile API yet), or build our own class file parser. I've generally been hesitant to add more dependencies to NullAway, as it can lead to versioning conflicts on users' processor paths. We already have an astubx parser and it's very simple.

    We also don't plan to drop astubx support anytime soon. Overall I lean towards 1.

    And yes, astubx is missing a couple of features right now. But I feel those could be added without too much trouble.

  2. vlsi commented on Nov 15, 2026

    @vlsi
    ContributorAuthor

    I implemented a prototype for classfile reader, see #2162 (comment)
    We need only a small subset of the classfile, so the reader is ~800 Java lines.

    It decodes a bit longer and takes a bit more space, however, going with a standard format is probably a nice thing on its own.

    WDYT?

  3. msridhar commented on Nov 16, 2026

    @msridhar
    Contributor

    Thanks for doing the experiment, @vlsi! I need to spend a bit more time thinking about this. I understand the downside of astubx is maintaining our own format. But I'm not sure we can just remove support for it, given that others may be dependent on it and JarInfer (which Uber still uses) also relies on it. Also, it does have some compactness and loading time advantages.

    Also, the class file format may evolve. I don't expect that to impact the loading code you wrote too often, but it could. If we translate to astubx during the build, we can then use a 3rd-party library like ASM to do the class file parsing (or, some day, the ClassFile API), and then rely on them to update things for new class file features. We just maintain astubx (de-)serialization.

    All that said I am unsure; there are positives and negatives on both sides. I'll think it over more. I welcome more discussion.

  4. msridhar commented on Nov 21, 2026

    @msridhar
    Contributor

    After further thought here, my feeling is we should preserve astubx, and implement a converter from @vlsi's stub jar files to astubx, and then get rid of our javac plugin. I feel the benefits of preserving astubx are worthwhile.

    @vlsi does this seem reasonable? We can then take an action item to prototype the alternate converter, which could make use of ASM or the like to parse the class files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions