3 Replies Latest reply on Jun 7, 2004 10:35 PM by Shigeru Chiba

    try catch in NewExpr

    Skarzhevskyy Newbie

      Actualy I wanted to catch exceptions in during Object creation
      So I did:

      public class NewCodeConverter extends ExprEditor {

      public void edit(NewExpr expr) throws CannotCompileException {
      StringBuffer code = new StringBuffer(300);
      code.append("{ try ");
      code.append("{ $_ = $proceed($$); }");
      code.append("catch (OutOfMemoryErrore) {...} }");

      but during execution I get:
      Exception in thread "main" java.lang.VerifyError:
      method: my_getmem signature: (I)V) Inconsistent stack height 0 != 2

      could you help?
      Also are thre a bugs database?

        • 1. Re: try catch in NewExpr
          Shigeru Chiba Expert

          The reason of that exception is that $_ is not initialized if an OutOfMemoryError exception is thrown.
          So the problem should be fixed if you assign some value to $_ in the catch block.

          I have also modified Javassist so that $_ is automatically initialized. If you use Javassist directly downloaded from the CVS head (or use an upcoming beta 3 or later), your code above should run without any problem.

          • 2. Re: try catch in NewExpr
            Skarzhevskyy Newbie

            During last week I made instrumentaton of a large project.
            And some time I have seen java.lang.VerifyError at run time.
            Is it posible to run code verification before saving class file?

            • 3. Re: try catch in NewExpr
              Shigeru Chiba Expert

              Currently, no.
              I'm putting error checking code to avoid
              wrong instrumentation, but it is not a simple
              thing to produce useful error messages.

              Also, I have to consider the range of possible
              instrumentation. For example, changing
              a public method to be private would cause
              VerifyError if some methods in another
              class access that method. Detecting this
              error before saving a class file is a complicated
              task under the current architecture of Javassist.

              It would be great if you give me back your
              experiences of VerifyError. I can improve
              erorr checking code.