2 Replies Latest reply on Jun 23, 2005 12:48 PM by chiba

    javassist.CannotCompileException: [source error] invalid ty

    romad

      When I call :

      CtMethod cm = ...
      cm.insertAfter("if ($_ == null);");
      

      for method which return int[], for ex:

      public int[] test() {
       int[] arr = {1,2};
       return arr;
       }
      


      I keep getting " javassist.CannotCompileException: [source error] invalid types for ==" exception.

      Is there any way to avoid it?

      thank you
      Roman

        • 1. Re:  javassist.CannotCompileException: [source error] invali
          romad

          I looked into source code and looks like array datatypes are not parsed correctly (int[] interpreted like int and later check for expression parameters doesn't like to have primitive and none primitive types mixed together or something like this)

          Anyway, in case somebody would have similar problem, one way to avoid it -
          is to wrap return value with $w and assign it to Object obj and use obj instead of $_. Not sure if it will work for all cases but at least should prevent compilation exception.

          for ex:

          cm.insertAfter("Object obj = (($w)$_); if (obj == null) ... ;");



          regards
          Roman


          • 2. Re:  javassist.CannotCompileException: [source error] invali
            chiba

            Thank you for your bug report.
            I have fixed it. Please download the latest snapshot
            from the CVS HEAD.