3 Replies Latest reply on Mar 24, 2005 9:44 AM by chiba

    VerifyError on javassist generated constructor

    jpschewe

      I'm generating classes on the fly using javassist and it seems that javassist is creating the incorrect bytecodes for super calls in constructors. I use this these API calls to create a constructor:
      final CtConstructor cons1 = new CtConstructor(new CtClass[] {
      pool.get("dome.interpretation.InterpretationFactory"),
      pool.get("dome.datamodel.FirstClassObject")
      }, clazz);
      cons1.setBody("super((dome.interpretation.InterpretationFactory)$0, (dome.datamodel.FirstClassObject)$1);");
      clazz.addConstructor(cons1);

      And when it runs get this error:
      java.lang.VerifyError: (class: dome/model/guid212906758570114/PlaceImpl, method: signature: (Ldome/interpretation/InterpretationFactory;Ldome/datamodel/FirstClassObject;)V) Expecting to find object/array on stack
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:242)
      at dome.interpretation.InterpretationFactory.createInstanceOf(InterpretationFactory.java:133)
      at dome.Test.main(Test.java)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at dome.Bootstrap.main(Bootstrap.java:33)

      It also seems odd that I need to cast $0 and $1 to their datatypes, however if I don't then the javassist compiler complains that it cannot find the appropriate method. This is also true in methods as well as constructors. Does anyone have any workarounds?