mardi 12 juillet 2016

All reflection methods accessing constructor of class generated through ASM throw NoClassDefFoundError if class references primitive type

I am writing an application in which reflected Method objects with specific signatures are unwrapped to regular INVOKEVIRTUAL calls in classes generated through ASM so that those methods can be repeatedly invoked in a more performance-conscious manner. Methods to be unwrapped will always have a specific return type and first parameter, but can have any given number of other parameters of any type past that point.

I have defined two classes to do this, InvokerProxy and NewInvokerProxyFactory. Through testing I have discovered that if the method being unwrapped by the InvokerProxyFactory has any primitive parameters (int, char, float, etc..), attempting to look up a constructor for that class through any of the normally provided reflection methods (Class#getConstructors, Class#getDeclaredConstructor, etc...) will result in a java.lang.NoClassDefFoundError citing the first primitive type found in the method signature as its message. The exception is apparently caused by URLClassLoader#findClass, where a ClassNotFoundException is thrown with the same message.

Apparently this issue going even beyond constructors since even Unsafe#allocateInstance throws this same exception when creating an instance of the generated class. There are also absolutely no issues looking up constructors or creating instances when the unwrapped method does not have any primitive parameters.

I am thoroughly stumped, and I would very much appreciate any help that anyone could provide!





Aucun commentaire:

Enregistrer un commentaire