question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypePool Illegal Resolution

See original GitHub issue

Problem description: We are using ByteBuddy with our Java agent (Kanela). We’re instrumenting some classes in the bootstrap classloader, injecting the advisor classes in this way:

public static void inject(File folder, Instrumentation instrumentation, java.util.List<Class<?>> allClasses) {
        ClassInjector.UsingInstrumentation
                .of(folder, ClassInjector.UsingInstrumentation.Target.BOOTSTRAP, instrumentation)
                .inject(collect(allClasses));
    }

private static Map<TypeDescription.ForLoadedType, byte[]> collect(List<Class<?>> allClasses) {
        return allClasses
                .stream()
                .collect(Collectors.toMap(TypeDescription.ForLoadedType::new, ClassFileLocator.ForClassLoader::read));
    }

using byte-buddy 1.8.22 and run fine.

Then when we update to byte-buddy 1.9.12 and change the inject method to:

public static void inject(File folder, Instrumentation instrumentation, java.util.List<Class<?>> allClasses) {
        ClassInjector.UsingInstrumentation
                .of(folder, ClassInjector.UsingInstrumentation.Target.BOOTSTRAP, instrumentation)
                .injectRaw(ClassFileLocator.ForClassLoader.readToNames(allClasses));
}

with this change leads to a TypePool.Resolution.Illegal with this stack:

[main] ERROR 2019-05-29 15:02:43  Logger : Error => java.util.concurrent.ScheduledThreadPoolExecutor with message Cannot resolve type description for kamon.executors.instrumentation.ExecutorsInstrumentationAdvisors$RunnableWrapperAdvisor. Class loader: Bootstrap ClassLoader: java.lang.IllegalStateException: Cannot resolve type description for kamon.executors.instrumentation.ExecutorsInstrumentationAdvisors$RunnableWrapperAdvisor
	at kanela.agent.libs.net.bytebuddy.pool.TypePool$Resolution$Illegal.resolve(TypePool.java:159)
	at kanela.agent.libs.net.bytebuddy.pool.TypePool$Default$WithLazyResolution$LazyTypeDescription.delegate(TypePool.java:1407)
	at kanela.agent.libs.net.bytebuddy.description.type.TypeDescription$AbstractBase$OfSimpleType$WithDelegation.getDeclaredMethods(TypeDescription.java:8045)
	at kanela.agent.libs.net.bytebuddy.asm.Advice.to(Advice.java:334)
	at kanela.agent.libs.net.bytebuddy.asm.Advice$WithCustomMapping.to(Advice.java:10946)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Transformer$ForAdvice$Entry$ForUnifiedAdvice.resolve(AgentBuilder.java:2528)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Transformer$ForAdvice.transform(AgentBuilder.java:2314)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Transformer$Compound.transform(AgentBuilder.java:2614)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple$Resolution.apply(AgentBuilder.java:10126)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:10551)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10514)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1500(AgentBuilder.java:10280)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:10890)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:10837)
	at java.security.AccessController.doPrivileged(Native Method)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10437)
	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 kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$RedefinitionStrategy$Dispatcher$ForJava6CapableVm.retransformClasses(AgentBuilder.java:6734)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$RedefinitionStrategy$Collector$ForRetransformation.doApply(AgentBuilder.java:7011)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$RedefinitionStrategy$Collector.apply(AgentBuilder.java:6860)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$RedefinitionStrategy.apply(AgentBuilder.java:4728)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Default.installOn(AgentBuilder.java:9272)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Default.installOn(AgentBuilder.java:9242)
	at kanela.agent.libs.net.bytebuddy.agent.builder.AgentBuilder$Default$Delegator.installOn(AgentBuilder.java:11235)
	at kanela.agent.builder.AgentInstaller.install(AgentInstaller.java:45)
	at kanela.agent.InstrumentationLoader.lambda$load$4(InstrumentationLoader.java:50)
	at kanela.agent.libs.io.vavr.collection.List.map(List.java:1017)
	at kanela.agent.InstrumentationLoader.load(InstrumentationLoader.java:42)
	at kanela.agent.Kanela.lambda$null$0(Kanela.java:78)

Thanks in advance and any advice is welcome!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
raphwcommented, Jun 26, 2019

Of course, this is obvious now that I think of it. Your agent’s class loader is not in a common hierarchy with the instrumented class’s loader and needs to be added explicitly to make Byte Buddy annotations available.

0reactions
dpsoftcommented, Jun 22, 2019

Hi, I’ve found the issue and for our use case with only change this:

new AgentBuilder.Transformer.ForAdvice()
                .advice(this.methodMatcher, advisorClass.getName())
                .withExceptionHandler(AdviceExceptionHandler.instance());

to this:

 new AgentBuilder.Transformer.ForAdvice()
                .advice(this.methodMatcher, advisorClass.getName())
                .include(advisorClass.getClassLoader())
                .withExceptionHandler(AdviceExceptionHandler.instance());

all is running like a charm!

Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypePool.Resolution.Illegal (Byte Buddy (with dependencies) 1.12 ...
A canonical representation of a non-successful resolution of a TypePool . Nested Class Summary. Nested classes/interfaces inherited from interface net.
Read more >
Byte Buddy - java.lang.IllegalStateException: Cannot resolve ...
The log line indicates that the KafkaProducer is loaded by the bootstrap loader. Is the producer somehow appended to this loader?
Read more >
ByteBuddy Enhancer throws java.lang.IllegalStateException
IllegalStateException: Cannot resolve type description for certain classes ... TypePool$Resolution$Illegal.resolve(TypePool.java:149) 4 at ...
Read more >
Error on instrumenting Weblogic Server with APM Agent Client ...
TypePool $Resolution$Illegal.resolve(TypePool.java:159 ) at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.
Read more >
com.fitbur.bytebuddy.pool.TypePool$Resolution.resolve java code ...
public TypeDescription getEnumerationType() { return typePool.describe(descriptor.substring(1, descriptor.length() - 1).replace('/', '.')).resolve();
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found