VerifyError被抛出是因为在类FooBar的构造函数中调用的方法实际上是类F的方法,而不是类Foo的方法。
我收到这个错误:
java.lang.VerifyError: Bad <init> method call in method FooBar.<init>(I)V at offset 2
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2404)
at java.lang.Class.getConstructor0(Class.java:2714)
at java.lang.Class.getDeclaredConstructor(Class.java:2002)
当试图访问我用ASM 4.0(使用jdk7)修改过的类的构造函数时。
我已经检查了该类初始化方法的字节码,如下所示:
aload_0
iload_1
invokespecial com/foo/F/<init>(I)V
return
分解字节码产生:
import com.foo.Foo;
public class FooBar extends Foo
{
public FooBar(int i)
{
super(i);
}
}
我完全不明白为什么我会收到这个错误。我不知道我是否提供了足够的信息;如果我能补充更多信息,请告诉我。
编辑:这是访问构造函数的代码:
Class fooBarClass = /* define class from class file bytes */;
Constructor fooBarConstructor = fooBarClass.getDeclaredConstructor(int.class);
编辑2:这是Foo:类的代码
public class Foo extends F {
public Foo(int i) {
super(i);
}
}
试着反编译类Foo并注意正确的构造函数。我打赌构造函数Foo(int)不存在。
类FooBar中对超级方法的常量池引用指向了错误的类(即F而不是Foo)。因此,会抛出VerifyError,并显示相应的消息"Bad method call"。