0
當我嘗試內聯兩個班出現一些異常:ClassFormatError:在<Unknown>類字段「_callee__a1」具有非法簽名「_callee」
public class CI_Caller1 {
private int _data;
private CI_Callee_2 _callee;
public CI_Caller1(int data, CI_Callee_2 callee){
_data = data;
_callee = callee;
}
}
public class CI_Callee_2 {
private Integer _a1;
private String _t;
public CI_Callee_2(Integer a1, String t){
_a1 = a1;
_t = t;
}
}
的inling操作是內聯兩個領域,_a和_t在CI_Callee_2 ,作爲CI_Caller1的成員。新成員是:
private int _data;
private Integer _callee__a1;
private String _callee__t;
一切似乎是正確的,但是當我嘗試加載生成的字節[],異常被拋出:
java.lang.ClassFormatError: Field "_callee__a1" in class <Unknown> has illegal signature "_callee"
at sun.misc.Unsafe.defineAnonymousClass(Native Method)
at code.jit.asm.services.ACLoader.loadClass(ACLoader.java:27)
的方式vistiField是這樣的:
_fieldNode = reference2CI_Callee_2FieldNode();
//cw is class visitor to the CI_Caller1
cw.visitField(_fieldNode.access, calculateName(fieldHoster, _fieldNode.name),
_fieldNode.desc, _fieldNode.signature, _fieldNode.value);
的_fieldNode
這裏一個CI_Callee_2
的領域,並引用其初始成員(及其值):
desc: Ljava/lang/Integer;
name: _a1 //calculateName will map _a1 to _callee_a1
signature: null
value: null
一旦使用CI_Callee_2的ClassNode初始化_fieldNode,我沒有做任何更改。 (_fieldNode的signature
值始終爲NULL)
是否有人看到此異常?謝謝。
仍然困惑。 1)我不明白爲什麼在生成的代碼中有簽名''_callee'',因爲visitField的'_fieldNode.signature'是NULL,它是用CI_Callee2的classNode初始化的(永遠不會改變)。 2)''簽名''和''desc''有什麼區別? 「Ljava/lang/Integer;」是描述,它已經正確地傳遞給cw.visitField作爲「desc」。 –
我已修復它。問題出在另一個地方,我通過錯誤的字符串'_callee'作爲putField指令的desc。 –
@shijie xu:ASM API使用的名稱有點令人誤解。 'desc'是其他地方被稱爲*簽名*,而'簽名'是可能爲'null'的*通用簽名*。 – Holger