byte-buddy: latest guava cause [ unexpected type reference on method: 16 ]

guava: 33.2.1-jre, byte-buddy: 1.14.18

When using byte-buddy to define java agent, some classes in Guava, such as Joiner, can result in the following errors:

java.lang.IllegalStateException: Unexpected type reference on method: 16
	at net.bytebuddy.pool.TypePool$Default$TypeExtractor$MethodExtractor.visitTypeAnnotation(TypePool.java:8791)
	at net.bytebuddy.jar.asm.ClassReader.readMethod(ClassReader.java:1453)
	at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:745)
	at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:425)
	at net.bytebuddy.pool.TypePool$Default.parse(TypePool.java:880)
	at net.bytebuddy.pool.TypePool$Default.doDescribe(TypePool.java:864)
	at net.bytebuddy.pool.TypePool$Default$WithLazyResolution.access$001(TypePool.java:944)
	at net.bytebuddy.pool.TypePool$Default$WithLazyResolution.doResolve(TypePool.java:1042)
	at net.bytebuddy.pool.TypePool$Default$WithLazyResolution$LazyTypeDescription.delegate(TypePool.java:1111)
	at net.bytebuddy.description.type.TypeDescription$AbstractBase$OfSimpleType$WithDelegation.getModifiers(TypeDescription.java:8540)
	at net.bytebuddy.description.type.TypeDescription$AbstractBase$OfSimpleType$WithDelegation.getModifiers(TypeDescription.java:8540)
	at net.bytebuddy.matcher.ModifierMatcher.doMatch(ModifierMatcher.java:60)
	at net.bytebuddy.matcher.ModifierMatcher.doMatch(ModifierMatcher.java:27)
	at net.bytebuddy.matcher.ElementMatcher$Junction$ForNonNullValues.matches(ElementMatcher.java:249)
	at net.bytebuddy.matcher.ElementMatcher$Junction$Disjunction.matches(ElementMatcher.java:214)
	at net.bytebuddy.agent.builder.AgentBuilder$RawMatcher$ForElementMatchers.matches(AgentBuilder.java:1973)
	at net.bytebuddy.agent.builder.AgentBuilder$RawMatcher$Disjunction.matches(AgentBuilder.java:1861)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:12504)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:12464)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1800(AgentBuilder.java:12173)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:12873)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:12811)
	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:12373)
	at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
	at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at com.test.TestMain.main(TestMain.java:10)

However, this problem does not arise when using Guava versions not exceeding 33.2.0-jre, despite the fact that the Joiner has remained unchanged. test-agent.zip test-project.zip

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 15 (8 by maintainers)

Most upvoted comments

You can do this. If you exclude them by their package prefix, the class will not be resolved. You will need to include this matcher first.

This is now handled and supported by a test. It will be released with the next version. Sorry for not taking care of this earlier.