2 Replies Latest reply on Aug 17, 2005 1:43 PM by Shigeru Chiba

    Register 1 in a java.lang.VerifyError

    Matthew Presley Newbie

      Receive the following VerifyError after inserting code before and after a toString() method in a class called TestObjectSuper:

      java.lang.VerifyError: (class: org/aero/sbedrock/TestObjectSuper, method: toString signature: ()Ljava/lang/String;) Register 1 contains wrong type
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:1655)
      at java.lang.Class.getDeclaredMethod(Class.java:1262)
      at javassist.Loader.run(Loader.java:273)
      at org.aero.sbedrock.SRun.main(SRun.java:58)

      I'm trying to narrow down the problem, but it would be very helpful if someone could tell me what exactly is in Register 1 validation of this method. Thanks.

        • 1. Re: Register 1 in a java.lang.VerifyError
          Matthew Presley Newbie

          More details:

          Here is the method I'm using to modify the toString() method in TestObjectSuper:

           private static void hackExistingMethod(CtMethod method) throws Exception {
           method.addLocalVariable("var", CtClass.booleanType);
           String methodStart = "{var = true;}";
           method.insertBefore(methodStart);
          
           String methodEnd = "{if (var) hashCode();}";
           method.insertAfter(methodEnd, true); // true --> do as finally
           }
          



          It compiles fine. I get the verify error shown above. Note that if I add the assignment var = true; at the beginning of the insertAfter block, then this compiles fine.

          Any idea what's going on here? Shouldn't I be able to access the add local variable "var" in the insertAfter block without problems since I initialize it in the insertBefore block?


          • 2. Re: Register 1 in a java.lang.VerifyError
            Shigeru Chiba Expert

            Sorry, it's spec.

            method.insertAfter(methodEnd, true); // true --> do as finally
            


            If the second parameter to insertAfter() is true, then the local
            variable declared by addLocalVariable() is not vivible in the
            code inserted by insertAfter(). If the second parameter is false,
            your code should work well.