byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

NoSuchTypeException: Cannot resolve type description for

Open zfyq124 opened this issue 3 years ago • 4 comments
trafficstars

my agent must start after the open-telemetry agent(https://github.com/open-telemetry), when my agent transform class occur an error

Failed to handle org.springframework.web.servlet.DispatcherServlet for transformation on classloader sun.misc.Launcher$AppClassLoader@18b4aac2
net.bytebuddy.pool.TypePool$Resolution$NoSuchTypeException: Cannot resolve type description for io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker
	at net.bytebuddy.pool.TypePool$Resolution$Illegal.resolve(TypePool.java:162)
	at net.bytebuddy.pool.TypePool$Default$WithLazyResolution$LazyTypeDescription.delegate(TypePool.java:1074)
	at net.bytebuddy.description.type.TypeDescription$AbstractBase$OfSimpleType$WithDelegation.getTypeVariables(TypeDescription.java:8294)
	at net.bytebuddy.description.type.TypeDescription$AbstractBase.isGenerified(TypeDescription.java:7920)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Reifying.onNonGenericType(TypeDescription.java:1692)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Reifying$1.onNonGenericType(TypeDescription.java:1648)
	at net.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType.accept(TypeDescription.java:3611)
	at net.bytebuddy.dynamic.scaffold.MethodGraph$Compiler$Default.doAnalyze(MethodGraph.java:632)
	at net.bytebuddy.dynamic.scaffold.MethodGraph$Compiler$Default.compile(MethodGraph.java:567)
	at net.bytebuddy.dynamic.scaffold.MethodGraph$Compiler$AbstractBase.compile(MethodGraph.java:465)
	at net.bytebuddy.dynamic.scaffold.MethodRegistry$Default.prepare(MethodRegistry.java:471)
	at net.bytebuddy.dynamic.scaffold.inline.RedefinitionDynamicTypeBuilder.make(RedefinitionDynamicTypeBuilder.java:204)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:10930)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10866)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1700(AgentBuilder.java:10584)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:11258)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:11205)
	at java.security.AccessController.doPrivileged(Native Method)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doPrivileged(AgentBuilder.java)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10773)
	at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
	at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
	at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
	at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.bytebuddy.utility.Invoker$Dispatcher.invoke(Unknown Source)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$Dispatcher$ForNonStaticMethod.invoke(JavaDispatcher.java:974)
	at net.bytebuddy.utility.dispatcher.JavaDispatcher$ProxiedInvocationHandler.invoke(JavaDispatcher.java:1098)
	at net.bytebuddy.agent.builder.$Proxy31.retransformClasses(Unknown Source)
	at net.bytebuddy.agent.builder.AgentBuilder$RedefinitionStrategy$Collector$ForRetransformation.doApply(AgentBuilder.java:7807)
	at net.bytebuddy.agent.builder.AgentBuilder$RedefinitionStrategy$Collector.apply(AgentBuilder.java:7622)
	at net.bytebuddy.agent.builder.AgentBuilder$RedefinitionStrategy.apply(AgentBuilder.java:5444)
	at net.bytebuddy.agent.builder.AgentBuilder$Default.doInstall(AgentBuilder.java:10149)
	at net.bytebuddy.agent.builder.AgentBuilder$Default.installOn(AgentBuilder.java:10062)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$Delegator.installOn(AgentBuilder.java:11592)

the reason is open-telemetry agent inject the class: io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker to bootstrap then transfromer the class DispatcherServlet, it will add VirtualFieldInstalledMarker to the class DispatcherServlet . but in hotspot the method appendToBootstrapClassLoaderSearch didn't add the jar file to url classpath, so call the ClassLoader.getResourceAsStream("io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker") return null

is there has a good method to fix this?

zfyq124 avatar Sep 20 '22 09:09 zfyq124

No, unfortunately. Unless if you capture the injection somehow, there is no good way to read the class's class file.

But why would you need to instrument these classes? You can normally safely ignore them. Another option is to transform these classes based on the loaded class. There is an option to "resubmit" classes when defining a retransformation strategy.

raphw avatar Sep 20 '22 19:09 raphw

But why would you need to instrument these classes? You can normally safely ignore them.

My agent will do some function base on the open-telemetry trace context so there are some class need to instrument on the open-telemetry transformed class. I can't ignore them.

Another option is to transform these classes based on the loaded class. There is an option to "resubmit" classes when defining a retransformation strategy.

Thanks for the suggestion, i will try it.

zfyq124 avatar Sep 21 '22 05:09 zfyq124

@raphw I had checked the "withResubmission" API, from my understanding resubmit will retransform the error class according to the ResubmissionSpecification. But i think the resubmit will error again because the ClassFileLocator can't locate the class. What do you mean "to transform these classes based on the loaded class"? I need to rewrite a ClassFileLocator to locate the class "io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker"? Thanks.

zfyq124 avatar Sep 21 '22 06:09 zfyq124

Within the resubmission, the class is loaded already and a type description can be based on that loaded class.

raphw avatar Sep 22 '22 11:09 raphw