Repository navigation
fix: unblock Byte Buddy 1.18.13 in CI, and fix the shaded agent and JAR defects it exposed - #16
Merged
Merged
Conversation
…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
This was referenced Sep 11, 2026
Closed
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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
packagephase.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-plugin3.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 rewritenet.bytebuddytonanometer.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-plugin3.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.ktscontains 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
mvn -DskipTests package -Dbytebuddy.version=1.18.13against shade 3.5.2.mvn clean verifyreports BUILD SUCCESS with 45 of 45 tests passing.nanometer/shaded/bytebuddy/, zero remaining undernet/bytebuddy/, and thePremain-Class,Agent-Class,Can-Redefine-ClassesandCan-Retransform-Classesmanifest entries all survive the plugin bump.NanometerAgent.installfrom"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.-javaagenton JDK 26 against a throwaway class and confirmed, via Byte Buddy's class dump, that it transforms the target and wires delegation tonanometer.agent.AutoMetricInterceptor.intercept.No regression test is added because the build is the gate:
mvn packagecannot 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.xmlfiles 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.
interceptwas never invoked: every transformation failed andAgentBuilder's default no-op listener swallowed it.MethodDelegationwith@SuperCallneeds auxiliary classes injected into the instrumented class's loader, which a modern JVM refuses. Byte Buddy 1.18's other strategies do not help:UsingUnsafeis disabled from Java 25, andUsingJnawould add a dependency to a zero-dependency toolkit. The agent now instruments withAdvice, which inlines into the target method and needs no auxiliary classes or injection, and also drops the per-callCallablethe hot path was never meant to pay for. Transformation failures now reachSystem.errinstead of vanishing.AutoMetricInterceptor.intercept(Method, Callable)is unchanged, so its public surface and existing tests hold; it and the advice hooks shareenterSpan/exitSpanso the recording logic is not duplicated.#17, unloadable multi-release entries. Excluded from the shaded JAR. The manifest has no
Multi-Releaseattribute, 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 enablingMulti-Releaselater would spring.Why neither was caught before: the surefire suite only ever sees the unshaded module classpath. This PR adds
maven-failsafe-plugintonanometer-apiso integration tests run afterpackageagainst the artifact that actually ships.ShadedAgentITforks 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.ShadedJarLayoutITasserts every class entry's path matches the class it declares, that there are no versioned entries and noMulti-Releaseattribute, that no unrelocatednet/bytebuddyororg/sqliteclasses leak, and that the agent manifest entries survive shading.Both were verified by deliberate breakage, not just by passing: reverting the transform to
MethodDelegationturns 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.classwhose class declaresnanometer.shaded.bytebuddy.jar.asmjdkbridge.AsmAttribute. The shaded JAR's manifest carries noMulti-Release: true, so the JVM ignoresMETA-INF/versions/*entirely and these entries are never loaded. The same mismatch already exists onmainfor the relocatedorg.sqliteentries underMETA-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