Verify Error: Inconsistent args_size for opc_invokeinterface
I have been trying to generate some dynamic codes (Using Javassist) but program fails at a certain point when involving a double array or float array. The code is as follows
Class c = Customers.class; // called in main & Customer class just has a d开发者_如何转开发ouble[] Dubs = new double[10]
CreateType(c); // Main
public static Object CreateType(Class genericType)
{
// some preReq declarations
CtMethod writeCode = dyn.getDeclaredMethod("processCode");
generateCode(genericType, Code, "temp"); // Code is a StringBuilder class
System.out.println(Code);
writeCode.insertAt(1, Code.toString()); // Compilation is successful
Class c = dyn.toClass();
Dynamic h;
Constructor[] ctorlist = null;
ctorlist = c.getDeclaredConstructors(); // Problem is here
h = (DynamicSurrogate) ctorlist[0].newInstance(genericType);
return h;
}
Generated code is as follows
testapp1.Customers temp=(testapp1.Customers)graph;
output.processDouble(temp.Dubs[1]);
But problem arises when getDeclaredConstructors is called c.getDeclaredConstructors() ... it throws the following error
Exception in thread "main" java.lang.VerifyError: (class: testapp1/Dyn, method: processDouble signature: (Lsomething/Output;Ljava/lang/Object;)V) Inconsistent args_size for opc_invokeinterface
A workaround exists but does not make any sense, i.e. everything works fine if i simply create a copy of the double array and pass it on to processDouble in dynamic code i.e. if the dynamic code is
testapp1.Customers temp=(testapp1.Customers)graph;
double[] d = temp.Dubs;
output.processDouble(d);
In short , exception Unhandled is thrown by getDeclaredConstructor but it actually has nothing to do with a constructor because it doesnt matter if i create one or not
Hopefully my problem and code is clear enough, if any confusion please do tell, Thankyou in advance :)
The verify error is thrown out of getDeclaredConstructors because that's the first place that the bytecodes in class c are verified.
As to the cause of the error, I suspect it has to do with the fact that in the first case you're passing a double, and in the second case a double[].
精彩评论