3 Replies Latest reply on Dec 13, 2004 9:02 AM by Shigeru Chiba

    addCatch doesn't work

    Reza Hay Newbie

      I used addCatch as follows:

      for (int i = 0; i < allMethods.length; i++) {
      CtMethod method = allMethods;
      if (method.getName().startsWith("set")) {
      StringBuffer insCode = new StringBuffer();
      //insCode.append("java.lang.StackTraceElement[] ste = $e.getStackTrace();");
      method.addCatch(insCode.toString(), expClass);

      When I look at the decompiled (by JAD) class-file, I see the instrumentation is done perfectly. But If I want to run the instrumented class-file I get the following error-msg from JVM:

      java.lang.VerifyError: (class: nl/vu/cs/iids/MyPoint, method: setRectangular signature: (DD)V) Falling off the end of the code

      MyPoint is an example class with a number of set-methods. (It is the example class which is shiped by AspectJ).

      I have tried also with the javassist 2.6. But I got the same problem.


        • 1. Re: addCatch doesn't work
          Shigeru Chiba Expert

          Can you do

          method.addCatch("{return;}", expClass);

          and make sure it works?

          There is a note in both the tutorial and the javadoc.

          Note that the inserted code fragment must end with a throw or return statement.

          Thank you!

          • 2. Re: addCatch doesn't work
            Reza Hay Newbie

            Thank you very, chiba for your response. I used {return;} and it works. But if there are methods with non-void return types then {return;} is not enough. Therefore I used (within my addCatch) {Object result; return ($r)result;}. But I get the following javassist compiler error:

            javassist.CannotCompileException: [source error] no such class: $r
            at javassist.CtBehavior.addCatch(CtBehavior.java:722)
            at javassist.CtBehavior.addCatch(CtBehavior.java:670)


            It seems that the javassist compiler doesn't recognize $r. Is it not allowed to use $r in the addCatch? Or do I do something wrong?

            Thanks in advance

            • 3. Re: addCatch doesn't work
              Shigeru Chiba Expert

              I think it's a bug of Javassist.
              I'll fix this bug within a few days. Please wait for a while.
              (Fixing that bug seems very easy but it takes time to write
              test code etc. I could not have time to do it today.)