opentelemetry-java-instrumentation: NoClassDefFoundError when building native image

Describe the bug NoClassDefFoundError when building native image

Steps to reproduce

  1. create a simple spring boot3 project
  2. executing this command for build native ./mvnw clean -Pnative native:compile native:build

What did you expect to see? Should build success

What did you see instead? causing this exception:

Caused by: java.lang.NoClassDefFoundError: io/opentelemetry/javaagent/tooling/field/VirtualFieldImplementationsGenerator
        at java.base/java.lang.Class.getDeclaringClass0(Native Method)
        at java.base/jdk.internal.reflect.GeneratedMethodAccessor33.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.SVMHost.getDeclaringClass(SVMHost.java:432)

What version are you using? 1.27.0(latest)

Environment Compiler: (e.g., “GraalVM 17.0.7+8.1”) OS: (e.g., “MacOs”)

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

Hi @jeanbisutti

After I had a deep discovery of this issue, I found io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$java$lang$Runnable$io$opentelemetry$javaagent$bootstrap$executors$PropagatedContext loaded by bootstart classloader in this line : https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/HelperInjector.java#L317

while the VirtualFieldImplementationsGenerator is loaded by AgentClassLoader.

After I changed to use AgentClassLoader to load io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$java$lang$Runnable$io$opentelemetry$javaagent$bootstrap$executors$PropagatedContext

this exception was gone