java - super class not assignable to class implemented during runtime by asm -
i have java class consist of inner interface, , plan implement implementation class during runtime asm bytecode injection.
package my.example; public class x{ public static interface xint{ public void getx(); } //the following class implement interface defined during runtime. //i put here show how implementation public static ximpl extend y implements xint{ public void getx(){//implementation code} } }
i sure asm code correct, thing after defining class , call class.forname("my.example.x$ximpl"), following error:
> bad <init> method call exception details: location: my/example/x$ximpl.<init>()v: invokespecial reason: type 'my/other/package/y' not assignable 'my/example/x$ximpl'
my guess class y not available during runtime yet? have no idea.. appreciated!
edit: way load ximpl simple:
defineclass("my.example.x$ximpl", getximplbyte()); class.forname("my.example.x$ximpl"); //fails here
the reason why im sure byte code , class loading method right because if define implementation class without extending other class, work fine
seems asm classloader isn't child of x
classloader, there 2 different classes (even though identical), can't casted each other.
try use:
method m = classloader.getdeclaredmethods("defineclass", string.class, byte[].class, int.class, int.class); m.setaccessible(true); m.invoke(x.class.getclassloader(), ...);
Comments
Post a Comment