3

When rebasing the class com.google.common.collect.ImmutableMultimap$Values from Google Guava, I get an IllegalArgumentException from ByteBuddy.

The inner class is a subclass of com.google.common.collect.ImmutableCollection whose method ImmutableList<E> createAsList() causes the problem.

Stacktrace:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot attach undefined variable: V
at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:1973)
at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:1896)
at net.bytebuddy.description.type.TypeDescription$Generic$OfTypeVariable$Symbolic.accept(TypeDescription.java:5551)
at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor.onParameterizedType(TypeDescription.java:1857)
at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onParameterizedType(TypeDescription.java:1896)
at net.bytebuddy.description.type.TypeDescription$Generic$OfParameterizedType.accept(TypeDescription.java:5017)
at net.bytebuddy.dynamic.Transformer$ForMethod$TransformedMethod.getReturnType(Transformer.java:377)
at net.bytebuddy.description.method.MethodDescription$AbstractBase.asTypeToken(MethodDescription.java:685)
at net.bytebuddy.dynamic.scaffold.MethodRegistry$Default$Prepared$Entry.resolveBridgeTypes(MethodRegistry.java:916)
at net.bytebuddy.dynamic.scaffold.MethodRegistry$Default$Prepared.compile(MethodRegistry.java:778)
at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining$RedefinitionClassVisitor.visit(TypeWriter.java:3281)
at net.bytebuddy.jar.asm.ClassReader.accept(Unknown Source)
at net.bytebuddy.jar.asm.ClassReader.accept(Unknown Source)
at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining.create(TypeWriter.java:3018)
at net.bytebuddy.dynamic.scaffold.TypeWriter$Default.make(TypeWriter.java:1617)
at net.bytebuddy.dynamic.scaffold.inline.RebaseDynamicTypeBuilder.make(RebaseDynamicTypeBuilder.java:198)
at net.bytebuddy.dynamic.scaffold.inline.AbstractInliningDynamicTypeBuilder.make(AbstractInliningDynamicTypeBuilder.java:90)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:2566)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase$Delegator.make(DynamicType.java:2668)
at cl.InnerClassLoader.loadClass(InnerClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at test.Stuff.<init>(Stuff.java:15)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at test.Main.main(Main.java:15)

I've created an example triggering the issue here: https://github.com/erikhakansson/bytebuddytest The test was modified from an earlier test I had so there might be some garbage in there.

To test, simply run mvn clean install and then run the resulting jar.

Most likely, I'm doing something wrong, but I can't figure out what, so please help! :)

erikh
  • 146
  • 9

1 Answers1

5

You have found a bug in Byte Buddy. I have resolved this issue (formerly incorrect in release 1.6.14) in Byte Buddy 1.4.17.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
  • Ah, I see. Anything I can do in the meantime to get around the issue? – erikh Jul 28 '16 at 12:14
  • The new version was released yesterday night so I would recommend to just update. – Rafael Winterhalter Jul 28 '16 at 15:12
  • Unfortunately, I get the same error with the new version. Could it be another issue? I updated the linked repo to use the new version. – erikh Jul 28 '16 at 20:30
  • Are you sure that you updated properly? I had downloaded your project and tested against it. – Rafael Winterhalter Jul 28 '16 at 23:12
  • I just double checked. Your `main` method returns without errors on a fresh check-out of your project. – Rafael Winterhalter Jul 29 '16 at 01:30
  • Huh, that's weird. I'll have to check again. I'll do it tonight when I'm by the computer again – erikh Jul 29 '16 at 04:08
  • I still get the error, but I realised it's for a different class now: `com.google.common.collect.ImmutableMultimap$EntryCollection` I'm running using jdk1.8.0_31 if that matters. – erikh Jul 31 '16 at 18:50
  • I updated the test to print out the classname it tries to load, but I suppose that doesn't matter if you can't reproduce it. :/ I'm going to try on a different environment to see if it's something environment specific. – erikh Jul 31 '16 at 18:51
  • Hi, I made sure there was no trace of the project and now I can reproduce the error; I will look into it, must have missed something. – Rafael Winterhalter Jul 31 '16 at 20:48
  • Ah, good to know. Then I'm not going crazy! :) Thanks for all the help! – erikh Aug 01 '16 at 06:31
  • No, you are not. Sorry for that. I already identified the core problem and I made a wrong assumption such that my fix made things worse. I have to factor out something before I can fix this problem but I am on it. I will include the fix in 1.4.17. – Rafael Winterhalter Aug 01 '16 at 08:49
  • The release is out on Maven Central. – Rafael Winterhalter Aug 01 '16 at 13:11
  • The latest version solved the issue! Thank you! (Unrelated: Is there a donation page for bytebuddy?) – erikh Aug 01 '16 at 21:34
  • @erikh There is not but this is not necessary. I am a consultant and the way Byte Buddy works for me is that it hopefully generates some business. I appreciate the guesture, though. – Rafael Winterhalter Aug 02 '16 at 08:16