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.

"Cannot resolve type description" when class is not present

See original GitHub issue

Hi!

We received a bug report in BlockHound ( https://github.com/reactor/BlockHound/issues/71 ) that looks more like a bug in ByteBuddy.

I was able to reproduce it with the following setup:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
        <version>2.2.1.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>net.bytebuddy</groupId>
        <artifactId>byte-buddy</artifactId>
        <version>1.10.2</version>
    </dependency>

    <dependency>
        <groupId>net.bytebuddy</groupId>
        <artifactId>byte-buddy-agent</artifactId>
        <version>1.10.2</version>
    </dependency>
</dependencies>
public static void main(String[] args) throws Exception {
    Instrumentation instrumentation = ByteBuddyAgent.install();

    String testClass = "ch.qos.logback.classic.Logger";

    new AgentBuilder.Default()
            .with(RedefinitionStrategy.RETRANSFORMATION)
            .with(InitializationStrategy.NoOp.INSTANCE)
            .with((PoolStrategy) (classFileLocator, classLoader) -> new TypePool.Default(
                    new CacheProvider.Simple(),
                    classFileLocator,
                    TypePool.Default.ReaderMode.FAST
            ))
            .with(AgentBuilder.Listener.StreamWriting.toSystemError().withErrorsOnly())

            .type(it -> testClass.equals(it.getName()))
            .transform((builder, typeDescription, classLoader, javaModule) -> {
                return builder.visit(Advice.to(TestAdvice.class).on(named("callAppenders")));
            })
            .installOn(instrumentation);

    Class.forName(testClass);
}

public static class TestAdvice {
    @Advice.OnMethodEnter
    public static void onEnter() {
    }
}

It fails with this exception:

java.lang.IllegalStateException: Cannot resolve type description for org.slf4j.event.LoggingEvent
	at net.bytebuddy.pool.TypePool$Resolution$Illegal.resolve(TypePool.java:159)
	at net.bytebuddy.pool.TypePool$Default$LazyTypeDescription$TokenizedGenericType.toErasure(TypePool.java:6241)
	at net.bytebuddy.pool.TypePool$Default$LazyTypeDescription$GenericTypeToken$Resolution$Raw$RawAnnotatedType.of(TypePool.java:3412)
	at net.bytebuddy.pool.TypePool$Default$LazyTypeDescription$GenericTypeToken$Resolution$Raw$RawAnnotatedType$LazyRawAnnotatedTypeList.get(TypePool.java:3511)
	at net.bytebuddy.pool.TypePool$Default$LazyTypeDescription$GenericTypeToken$Resolution$Raw$RawAnnotatedType$LazyRawAnnotatedTypeList.get(TypePool.java:3456)
	at net.bytebuddy.pool.TypePool$Default$LazyTypeDescription$LazyMethodDescription$LazyParameterDescription.getType(TypePool.java:6994)
	at net.bytebuddy.description.method.ParameterDescription$AbstractBase.asToken(ParameterDescription.java:178)
	at net.bytebuddy.description.method.ParameterDescription$AbstractBase.asToken(ParameterDescription.java:128)
	at net.bytebuddy.description.method.ParameterList$AbstractBase.asTokenList(ParameterList.java:98)
	at net.bytebuddy.description.method.MethodDescription$AbstractBase.asToken(MethodDescription.java:825)
	at net.bytebuddy.description.method.MethodDescription$AbstractBase.asToken(MethodDescription.java:376)
	at net.bytebuddy.description.method.MethodList$AbstractBase.asTokenList(MethodList.java:70)
	at net.bytebuddy.dynamic.scaffold.InstrumentedType$Factory$Default$1.represent(InstrumentedType.java:364)
	at net.bytebuddy.ByteBuddy.rebase(ByteBuddy.java:851)
	at net.bytebuddy.agent.builder.AgentBuilder$TypeStrategy$Default$1.builder(AgentBuilder.java:2007)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple$Resolution.apply(AgentBuilder.java:10117)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:10494)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10457)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1500(AgentBuilder.java:10223)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$Java9CapableVmDispatcher.run(AgentBuilder.java:10907)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$Java9CapableVmDispatcher.run(AgentBuilder.java:10845)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10413)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$ByteBuddy$ModuleSupport.transform(Unknown Source)
	at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
	at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:563)
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:315)
	at reactor.SampleReactor.main(SampleReactor.java:39)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
raphwcommented, Nov 22, 2019

It’s less a bug than it’s a feature. “Optional types” is something several developers assume for the JVM to work due to it’s implicit type resolution but for legally transforming a type, all signature type information needs to be available during instrumentation.

Byte Buddy requires all type information for a transformed type to be available but for ch.qos.logback.classic.Logger, it cannot find org.slf4j.event.LoggingEvent. It is the equivalent exception to:

Class.forName("ch.qos.logback.classic.Logger").getDeclaredMethods()

Introspection only works if the introspected types are available. The good news is that this does not break anything but only aborts the instrumentation of the incomplete type.

0reactions
raphwcommented, Dec 11, 2019

I assume the question is answered, therefore I am closing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot resolve type description for java.lang.Exception`, and ...
It seems that the class loader that's being queried for the type description is not providing the desired classes. Is there a way...
Read more >
How to Fix the Type Not Present Exception in Java - Rollbar
Java's TypeNotPresentException is thrown when the definition of a type, attempted to be accessed using a specified name, cannot be found.
Read more >
ByteBuddy Enhancer throws java.lang.IllegalStateException
ByteBuddy Enhancer throws java.lang.IllegalStateException: Cannot resolve type description for certain classes ; Reporter ; Fix versions. 5.2.6 ...
Read more >
"Cannot resolve class" errors in layout xml files - Issue Tracker
ButtonBarLayout" "Cannot resolve class Space" Other widget classes are properly resolved, clearing Android Studio cache had no effect.
Read more >
Trying external-plugin-test on "real setup" fails with "Cannot ...
Hey there, when I try out the external-plugin-test from integration-tests, it fails with "Cannot resolve type description for ...
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