首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BCEL更新异常表

BCEL更新异常表
EN

Stack Overflow用户
提问于 2013-10-20 10:49:18
回答 1查看 191关注 0票数 0

我想用BCEL改变一个方法。但我不知道如何更新异常表。以下是简化的代码:

代码语言:javascript
复制
ConstantPoolGen poolGen = classGen.getConstantPool();
InstructionList iList = new InstructionList(method.getCode().getCode());
MethodGen newMethodGen = new MethodGen(method, classGen.getClassName(), poolGen);
for (InstructionHandle handle : iList.getInstructionHandles().clone()) {
    if (I_WANT_TO_WRAP_IT(handle)) {
         iList.insert(handle, MAKE_WRAPPER(handle));
         iList.delete(handle);
    }
}
classGen.removeMethod(method);
newMethodGen.setMaxStack();
newMethodGen.setMaxLocals();
classGen.addMethod(newMethodGen.getMethod());

在此之后,字节码被正确修改,但异常表与导致ClassFormatError的异常表保持不变,因为异常表指向不存在的PC。知道怎么处理这事吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-21 16:25:59

通常,您不需要处理这一点,因为BCEL应该处理它。在我看来,你的错误是使用与MethodGen不同的指令列表。因此,您正在修改底层代码,但是偏移没有得到正确处理。

试着使用

代码语言:javascript
复制
MethodGen newMethodGen = new MethodGen(method, classGen.getClassName(), poolGen);
InstructionList iList = newMethodGen.getInstructionList();

以确保代码和MethodGen使用相同的列表。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19476483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档