Skip to content

fix: unblock Byte Buddy 1.18.13 in CI, and fix the shaded agent and JAR defects it exposed - #16

Merged
PIsberg merged 1 commit into
mainfrom
fix/shade-plugin-mrjar-bytebuddy
Sep 11, 2026
Merged

PIsberg merged 1 commit into
mainfrom
fix/shade-plugin-mrjar-bytebuddy

Conversation

@PIsberg

@PIsberg PIsberg commented Sep 11, 2026 •

Copy link
Copy Markdown
Owner

Supersedes #10.

The failure

Every Maven job in #10 failed on JDK 21, 25 and 26 with the same error, while every Gradle job passed:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.5.2:shade (default)
  on project nanometer-api: Error creating shaded jar: Problem shading JAR
  .../byte-buddy-1.18.13.jar entry
  META-INF/versions/24/net/bytebuddy/jar/asmjdkbridge/JdkClassWriter$1.class:
  java.lang.IllegalArgumentException: Unsupported class file major version 68

Why it failed

The defect is in the build plugin, not in the dependency or in our code. All 45 tests passed in the failing runs; the build died afterwards, in the package phase.

Byte Buddy 1.18.x ships as a multi-release JAR. Its META-INF/versions/24/ entries are compiled at class file major version 68 (Java 24) so Byte Buddy can use the JDK ClassFile API where it is available. maven-shade-plugin 3.5.2 bundles ASM 9.6, which rejects any class above major 65 (Java 21). Shade has to read every class in a relocated dependency in order to rewrite net.bytebuddy to nanometer.shaded.bytebuddy, so it hits those entries and aborts.

This is why the JDK version in the matrix made no difference: the limit belongs to the ASM inside the plugin, not to the JDK running the build.

maven-shade-plugin 3.6.2 bundles ASM 9.9.1, which reads them. It requires Maven 3.6.3 or newer; CI runs 3.9.x.

The Gradle jobs were not evidence

All three Gradle jobs stayed green on #10. That did not mean the bump was safe. build.gradle.kts contains no shading configuration at all, so the Gradle build never rewrites the Byte Buddy JAR and never executes the code path that fails. A green Gradle job here says nothing about the Maven artifact.

What was verified

  • Reproduced the exact error locally on Maven 3.9.16 / JDK 26 by running mvn -DskipTests package -Dbytebuddy.version=1.18.13 against shade 3.5.2.
  • After the bump, mvn clean verify reports BUILD SUCCESS with 45 of 45 tests passing.
  • Inspected the produced shaded JAR: 3163 entries under nanometer/shaded/bytebuddy/, zero remaining under net/bytebuddy/, and the Premain-Class, Agent-Class, Can-Redefine-Classes and Can-Retransform-Classes manifest entries all survive the plugin bump.
  • Confirmed shade rewrote the string constant in NanometerAgent.install from "net.bytebuddy." to "nanometer.shaded.bytebuddy.", so the agent's self-ignore matcher still matches the relocated packages rather than silently instrumenting its own instrumentation library.
  • Ran the shaded JAR as -javaagent on JDK 26 against a throwaway class and confirmed, via Byte Buddy's class dump, that it transforms the target and wires delegation to nanometer.agent.AutoMetricInterceptor.intercept.

No regression test is added because the build is the gate: mvn package cannot produce the shaded artifact if the plugin cannot read a dependency's class files, and CI runs that on all three JDKs. Breaking the fix (reverting to 3.5.2) reproduces the red immediately.

No VibeTags annotations were considered warranted: the change touches only pom.xml files and adds no Java element.

Both follow-up issues are now fixed here too

The PR originally filed #17 and #18 as follow-ups. Both are fixed in this branch.

#18, the shaded agent recorded nothing. The cause was not the class-loader split guessed in the issue. intercept was never invoked: every transformation failed and AgentBuilder's default no-op listener swallowed it.

java.lang.IllegalStateException: Reflection-based injection is not available on the current VM
  at AgentBuilder$InjectionStrategy$UsingReflection.resolve
  at AgentBuilder$InitializationStrategy$SelfInjection$Split$Dispatcher.register

MethodDelegation with @SuperCall needs auxiliary classes injected into the instrumented class's loader, which a modern JVM refuses. Byte Buddy 1.18's other strategies do not help: UsingUnsafe is disabled from Java 25, and UsingJna would add a dependency to a zero-dependency toolkit. The agent now instruments with Advice, which inlines into the target method and needs no auxiliary classes or injection, and also drops the per-call Callable the hot path was never meant to pay for. Transformation failures now reach System.err instead of vanishing.

AutoMetricInterceptor.intercept(Method, Callable) is unchanged, so its public surface and existing tests hold; it and the advice hooks share enterSpan/exitSpan so the recording logic is not duplicated.

#17, unloadable multi-release entries. Excluded from the shaded JAR. The manifest has no Multi-Release attribute, so the JVM already ignored all 31 entries; removing them deletes bytes that could never execute rather than changing behaviour, and removes the trap that enabling Multi-Release later would spring.

Why neither was caught before: the surefire suite only ever sees the unshaded module classpath. This PR adds maven-failsafe-plugin to nanometer-api so integration tests run after package against the artifact that actually ships.

  • ShadedAgentIT forks a JVM with -javaagent:<shaded jar> and asserts spans are recorded, that a nested call inherits its caller's trace id and points at the caller's span, and that a throwing method records its exception type.
  • ShadedJarLayoutIT asserts every class entry's path matches the class it declares, that there are no versioned entries and no Multi-Release attribute, that no unrelocated net/bytebuddy or org/sqlite classes leak, and that the agent manifest entries survive shading.

Both were verified by deliberate breakage, not just by passing: reverting the transform to MethodDelegation turns all three agent tests red, and removing the shade filter turns both layout tests red naming all 31 entries. The unit suite passes through both breakages, which is the gap these tests close.

mvn clean verify: BUILD SUCCESS, 45 unit tests and 7 integration tests.

Original limitation note, retained for history

Shade rewrites the contents of multi-release entries but leaves their paths unrelocated, producing entries such as META-INF/versions/24/net/bytebuddy/.../AsmAttribute.class whose class declares nanometer.shaded.bytebuddy.jar.asmjdkbridge.AsmAttribute. The shaded JAR's manifest carries no Multi-Release: true, so the JVM ignores META-INF/versions/* entirely and these entries are never loaded. The same mismatch already exists on main for the relocated org.sqlite entries under META-INF/versions/9/, so this predates the bump; this change adds 32 more such entries. Filed as #17, and fixed in this branch.

Separately, I found that the shaded agent transforms target classes but records nothing into AutoMetricInterceptor's ring buffer when run as -javaagent. I verified this behaves identically with Byte Buddy 1.14.12 and 1.18.13, so it is pre-existing and not caused by this bump. Filed as #18, and fixed in this branch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01V84rqTx2rsorFLrGWHk4B4

…n be shaded

Bumping bytebuddy.version past 1.14.12 failed every Maven CI job on JDK 21,
25 and 26 with:

  Failed to execute goal maven-shade-plugin:3.5.2:shade on project nanometer-api:
  Problem shading JAR byte-buddy-1.18.13.jar entry
  META-INF/versions/24/net/bytebuddy/jar/asmjdkbridge/JdkClassWriter$1.class:
  java.lang.IllegalArgumentException: Unsupported class file major version 68

The failure is in the build plugin, not in the code: all 45 tests passed
before shade ran. Byte Buddy 1.18.x ships as a multi-release JAR whose
META-INF/versions/24 entries are compiled at class file major version 68
(Java 24). maven-shade-plugin 3.5.2 bundles ASM 9.6, which refuses any class
above major 65 (Java 21), so it aborts while rewriting those entries.
Plugin 3.6.2 bundles ASM 9.9.1 and reads them. It requires Maven 3.6.3+;
CI runs 3.9.x.

The Gradle jobs stayed green throughout and were not evidence the bump was
safe: build.gradle.kts performs no shading at all, so it never rewrites the
Byte Buddy JAR and never exercises the failing path.

Verified, not assumed:
- Reproduced the exact error locally on Maven 3.9.16 / JDK 26 with
  -Dbytebuddy.version=1.18.13 against shade 3.5.2.
- After the bump, `mvn clean verify` is BUILD SUCCESS with 45/45 tests passing.
- Inspected the resulting shaded JAR: 3163 entries relocated to
  nanometer/shaded/bytebuddy/, zero left under net/bytebuddy/, and the
  Premain-Class / Agent-Class / Can-Retransform-Classes manifest entries
  survive the plugin bump.
- Shade rewrote the string constant in NanometerAgent.install from
  "net.bytebuddy." to "nanometer.shaded.bytebuddy.", so the self-ignore
  matcher still matches the relocated packages.
- Ran the shaded JAR as a -javaagent on JDK 26 and confirmed via Byte Buddy's
  class dump that it transforms a target class and wires delegation to
  nanometer.agent.AutoMetricInterceptor.intercept.

The build itself is the regression gate here: `mvn package` cannot produce
the shaded artifact if the plugin cannot read a dependency's class files, and
CI runs it on all three JDKs.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01V84rqTx2rsorFLrGWHk4B4
@PIsberg
PIsberg merged commit 9f9352a into main Sep 11, 2026
9 checks passed
@PIsberg PIsberg changed the title fix(build): bump maven-shade-plugin to 3.6.2 so Byte Buddy 1.18.13 can be shaded fix: unblock Byte Buddy 1.18.13 in CI, and fix the shaded agent and JAR defects it exposed Sep 11, 2026
PIsberg added a commit that referenced this pull request Sep 11, 2026
)

Byte Buddy ships its JDK ClassFile API bridge only under META-INF/versions/24,
and uses it in place of its bundled ASM on JDK 24 and newer. The shaded JAR
could not reach it. #17 excluded the versioned entries because shade rewrites
their bytecode to the relocated package but leaves their paths alone, so they
declared one class and lived at another's path. Excluding them was correct
while that mismatch stood, but it made the fallback to bundled ASM permanent.

Staying on bundled ASM means every new class file version needs a Byte Buddy
upgrade before it can even be read, which is exactly the failure that produced
#16: shade 3.5.2's ASM 9.6 could not read Byte Buddy's own major-68 classes.

The paths can be relocated after all. maven-shade-plugin has no dedicated
support for multi-release entries, but its relocator matches on path prefix, so
naming the versioned prefix as a relocation pattern of its own moves the entry:

  META-INF.versions.24.net.bytebuddy -> META-INF.versions.24.nanometer.shaded.bytebuddy
  META-INF.versions.9.org.sqlite     -> META-INF.versions.9.nanometer.shaded.sqlite

Those patterns never match a class reference in bytecode, so they change only
entry paths; the existing net.bytebuddy and org.sqlite relocations keep doing
the content rewriting. With the paths in agreement, Multi-Release: true becomes
safe to declare and the versioned classes become loadable.

Both artifacts' versioned entries are additive rather than overriding: 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.

module-info and OSGi metadata stay excluded. An uber-JAR merges packages from
many modules, so a module descriptor cannot be correct, and OSGi metadata
describes a bundle this artifact is not.

Tests, replacing the inverted invariant from #17:
- isACoherentMultiReleaseJar asserts the flag and the entries agree in both
  directions, so neither can be introduced without the other.
- exposesTheClassFileApiBridgeOnSupportedRuntimes asserts the bridge resolves on
  JDK 24+ and is correctly invisible below it. It asserts both branches rather
  than skipping under 24, so it proves something on every JDK in the matrix
  instead of going quiet on one third of it.
- relocationIsComplete now strips the version prefix before checking, so a
  relocation covering only the base JAR no longer slips past it.
- classPathsMatchDeclaredNames is unchanged and now covers the versioned
  entries too, which is what makes enabling Multi-Release safe.

Verified by deliberate breakage:
- 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.
- Confirmed the relocated bridge class loads from the shaded JAR on JDK 26, and
  that all four agent ITs still pass with multi-release enabled, which is the
  real risk: Byte Buddy may now take the ClassFile API path when transforming.

Verified on both build systems and both ends of the JDK range: mvn clean verify
BUILD SUCCESS on JDK 26 and on JDK 21, 45 unit tests and 9 integration tests;
gradle build BUILD SUCCESSFUL. The JDK 21 run also hits a pre-existing failure
in nanometer-example's dynamic self-attach test that reproduces on the
unmodified commit on this machine and passes in CI, so it is a local JDK issue
and not from this change.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01V84rqTx2rsorFLrGWHk4B4
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