Skip to content

Fix VerifyError when using class-inject with -Xverify:all#97

Merged
mcculls merged 1 commit into
mainfrom
mcculls/class-inject-with-xverifyall
Jul 17, 2026
Merged

Fix VerifyError when using class-inject with -Xverify:all#97
mcculls merged 1 commit into
mainfrom
mcculls/class-inject-with-xverifyall

Conversation

@mcculls

@mcculls mcculls commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

What Does This Do

The originalError local was stored as the first instruction inside the try range that protects it, so the verifier's async-exception frame at the handler couldn't assume it was initialized, causing a VerifyError on JVMs that verify bootstrap-loader-defined classes (e.g. -Xverify:all). Move the try range to start after the store instead.

Motivation

Fixes:

java.lang.UnsupportedOperationException
  at datadog.instrument.classinject.ClassInjector.enableClassInjection(ClassInjector.java:141)
  at datadog.trace.bootstrap.Agent.start(Agent.java:226)
  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
  at java.base/java.lang.reflect.Method.invoke(Method.java:580)
  at datadog.trace.bootstrap.AgentBootstrap.agentmainImpl(AgentBootstrap.java:166)
  at datadog.trace.bootstrap.AgentBootstrap.agentmain(AgentBootstrap.java:73)
  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
  at java.base/java.lang.reflect.Method.invoke(Method.java:580)
  at datadog.trace.bootstrap.AgentPreCheck.continueBootstrap(AgentPreCheck.java:172)
  at datadog.trace.bootstrap.AgentPreCheck.agentmain(AgentPreCheck.java:27)
  at datadog.trace.bootstrap.AgentPreCheck.premain(AgentPreCheck.java:20)
  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
  at java.base/java.lang.reflect.Method.invoke(Method.java:580)
  at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:560)
  at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:572)
Caused by: java.lang.VerifyError
  at java.base/java.lang.ClassLoader.defineClass0(Native Method)
  at java.base/java.lang.System$2.defineClass(System.java:2395)
  at java.base/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2505)
  at java.base/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClassAsLookup(MethodHandles.java:2484)
  at java.base/java.lang.invoke.MethodHandles$Lookup.defineHiddenClass(MethodHandles.java:2150)
  at java.base/java.lang.Class.forName(Unknown Source)
  at datadog.instrument.classinject.ClassInjector.injectViaForName(ClassInjector.java:179)
  at datadog.instrument.classinject.ClassInjector.enableClassInjection(ClassInjector.java:139)
  ... 14 more

On systems with strict class verification turned on for all classes, such as -Xverify:all

Note when this fails the downstream agent falls back to a different approach, so there's no actual impact on the application - but this fix will stop it from having to do that fall back on those few deployments with full verification enabled.

Contributor Checklist

Jira ticket: [PROJ-IDENT]

The originalError local was stored as the first instruction inside the
try range that protects it, so the verifier's async-exception frame at
the handler couldn't assume it was initialized, causing a VerifyError
on JVMs that verify bootstrap-loader-defined classes (e.g. -Xverify:all).
Move the try range to start after the store instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mcculls mcculls added bug Something isn't working ai-assisted labels Jul 17, 2026
@mcculls
mcculls requested a review from a team as a code owner July 17, 2026 14:32
@mcculls
mcculls requested a review from ygree July 17, 2026 14:32
@mcculls mcculls changed the title Fix VerifyError in boot-class defineClass glue bytecode Fix VerifyError when using class-inject with -Xverify:all Jul 17, 2026
@mcculls
mcculls requested a review from amarziali July 17, 2026 14:34
@datadog-prod-us1-6

This comment has been minimized.

@mcculls
mcculls requested a review from PerfectSlayer July 17, 2026 14:48

@ygree ygree left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

@mcculls
mcculls merged commit 145620a into main Jul 17, 2026
8 checks passed
@github-actions github-actions Bot added this to the 0.1.0 milestone Jul 17, 2026
@mcculls
mcculls deleted the mcculls/class-inject-with-xverifyall branch July 17, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants