Skip to content

Shaded Byte Buddy falls back to bundled ASM instead of the JDK ClassFile API on JDK 24+ #20

Closed

Description

@PIsberg

What

Byte Buddy 1.18 ships a JDK ClassFile API bridge (net.bytebuddy.jar.asmjdkbridge) in META-INF/versions/24/, so that on JDK 24 and newer it can use the platform's own class file reader and writer instead of its bundled ASM.

The shaded nanometer-api-*-all.jar does not use it. PR #19 excludes META-INF/versions/** from the shaded artifact, so on every JDK the shaded Byte Buddy uses its bundled ASM.

This is not a regression

The entries were never loaded before either. The shaded manifest carries no Multi-Release attribute, so the JVM ignored META-INF/versions regardless, and the relocated entries had mismatched paths that would have failed to load anyway (see #17). PR #19 turned an accident into an explicit, tested decision. It did not change what executes.

Recording it because #17 is closed by that PR and this consequence should not disappear with it.

Why it might be worth revisiting

What it would take

maven-shade-plugin cannot relocate META-INF/versions/N/ entry paths, which is the whole reason the entries were broken. Making the bridge usable needs all three of:

  1. A way to relocate versioned entry paths, most likely a custom shade ResourceTransformer, or moving off shade for this artifact.
  2. Multi-Release: true added to the shaded manifest.
  3. A test that actually loads a versioned class on JDK 24+, since ShadedJarLayoutIT currently asserts the opposite invariant and would need inverting.

Item 3 matters most. Enabling 1 and 2 without it would reintroduce exactly the silent breakage #17 described.

Acceptance

Either implement the three items above with a test that proves the bridge is loaded on JDK 24+ and still correct after relocation, or close this as a deliberate and documented choice to stay on bundled ASM.

Activity

  1. PIsberg commented on Sep 11, 2026

    @PIsberg
    OwnerAuthor

    Fixed in PR #19, taking the implement path rather than the close-as-documented path.

    The blocker in the issue was item 1: maven-shade-plugin cannot relocate META-INF/versions/N/ entry paths. It turns out it can, without a custom ResourceTransformer. Shade's relocator matches on path prefix, so naming the versioned prefix as a relocation pattern of its own moves the entry:

    <relocation>
        <pattern>META-INF.versions.24.net.bytebuddy</pattern>
        <shadedPattern>META-INF.versions.24.nanometer.shaded.bytebuddy</shadedPattern>
    </relocation>
    <relocation>
        <pattern>META-INF.versions.9.org.sqlite</pattern>
        <shadedPattern>META-INF.versions.9.nanometer.shaded.sqlite</shadedPattern>
    </relocation>

    Those patterns never match a class reference in bytecode, so they affect only entry paths. The existing net.bytebuddy and org.sqlite relocations keep rewriting the contents. Result:

    META-INF/versions/24/nanometer/shaded/bytebuddy/jar/asmjdkbridge/JdkClassReader.class
      declares nanometer.shaded.bytebuddy.jar.asmjdkbridge.JdkClassReader
    

    Path and declared name agree, so item 2, Multi-Release: true, is now safe to declare.

    Item 3 was the one that mattered, and it is covered without a skip. exposesTheClassFileApiBridgeOnSupportedRuntimes asserts both directions: on JDK 24+ the bridge must resolve, and below 24 it must not. That way it proves something on every JDK in the CI matrix rather than going quiet on a third of it, and it would catch versioned classes leaking into the base JAR where an older JVM would load them.

    The old carriesNoMultiReleaseEntries assertion from #17 is inverted into isACoherentMultiReleaseJar, which requires the flag and the versioned entries to agree in both directions so neither can be introduced without the other. relocationIsComplete now strips the version prefix before checking, so a relocation covering only the base JAR cannot slip past it.

    Worth recording for anyone revisiting this: both artifacts' versioned entries are additive. Neither net/bytebuddy/jar/asmjdkbridge nor org/sqlite/nativeimage exists in its base JAR, so enabling multi-release adds classes rather than swapping an implementation underneath the base one. That is what made this low-risk. module-info and OSGi metadata stay excluded; an uber-JAR merges packages from many modules and cannot carry a correct descriptor.

    Verified by deliberate breakage, not just by passing:

    • Removing Multi-Release: true turns isACoherentMultiReleaseJar and the bridge test red.
    • Removing the two versioned relocations turns classPathsMatchDeclaredNames, relocationIsComplete and the bridge test red, naming all 31 entries.
    • The relocated bridge class was confirmed to load from the shaded JAR on JDK 26.
    • All four agent ITs still pass with multi-release enabled, which was the real risk here: Byte Buddy may now take the JDK ClassFile API path when transforming, rather than its bundled ASM.

    mvn clean verify is BUILD SUCCESS on JDK 26 and on JDK 21, and gradle build is BUILD SUCCESSFUL.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions