我一直在嘗試生成一些動態代碼(使用Javassist),但是當涉及雙數組或浮點數組時,程序在某個點失敗。代碼如下所示驗證錯誤:opc_invokeinterface的args_size不一致
Class c = Customers.class; // called in main & Customer class just has a double[] 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;
}
生成的代碼如下
testapp1.Customers temp=(testapp1.Customers)graph;
output.processDouble(temp.Dubs[1]);
但是問題出現時getDeclaredConstructors被稱爲c.getDeclaredConstructors()...這將引發以下錯誤
異常線程「main」java.lang.VerifyError:(class:testapp1/Dyn,method:processDouble signature:(Lsomething/Output; Ljava/lang/Object;)V)opc_invokeinterface的args_size不一致
一種解決方法,但沒有任何意義,即一切工作正常,如果我只需要創建一個雙數組的一個拷貝,並把它傳遞給processDouble動態代碼 即如果動態代碼是
testapp1.Customers temp=(testapp1.Customers)graph;
double[] d = temp.Dubs;
output.processDouble(d);
在簡單,異常getDeclaredConstructor引發未處理,但它實際上與構造函數無關,因爲它無關緊要,如果我創建一個或不是
希望我的問題和代碼足夠清楚,如果有任何混淆請告訴,Thankyou in提前:)