2

I'm receiving this error:

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)

when attempting to access the constructor of a class that I have modified with ASM 4.0 (using jdk7).

I have checked the bytecode for the initialization method of the class and it is as follows:

aload_0
iload_1
invokespecial com/foo/F/<init>(I)V
return

Decompiling the bytecode produces:

import com.foo.Foo;

public class FooBar extends Foo
{
  public FooBar(int i)
  {
    super(i);
  }
}

I'm completely stumped as to why I am receiving this error. I don't know if I've given enough information; please let me know if I can add any more information.

EDIT: Here is the code that is accessing the constructor:

Class fooBarClass = /* define class from class file bytes */;
Constructor fooBarConstructor = fooBarClass.getDeclaredConstructor(int.class);

EDIT2: Here is the code for the class Foo:

public class Foo extends F {

    public Foo(int i) {
        super(i);
    }
}
mburke13
  • 350
  • 2
  • 6
  • 22

2 Answers2

2

Try to decompile class Foo and watch for the proper constructor. My bet is constructor Foo(int) does not exist.

enTropy
  • 621
  • 4
  • 14
  • The class Foo has a constructor with one integer parameters and no others parameters. I will add that information to the question. – mburke13 Jul 24 '12 at 00:18
1

The VerifyError is being thrown because the method that is being invoked in the constructor of class FooBar is actually the method of class F and not class Foo.

The constant pool reference to the super method in class FooBar was to the wrong class (i.e. F instead of Foo). Because of this, a VerifyError is thrown with the corresponding message "Bad method call".

mburke13
  • 350
  • 2
  • 6
  • 22