1 Reply Latest reply on Sep 19, 2003 10:49 AM by chiba

    javassist.CannotCompileException after modifying a class



      I try to modify a class 'myclass'
      witch imports java.util.*.

      If the 'update'-code contains a creation
      of a new Object instance
      ArrayList() al = new ArrayList()
      without package-qualification a

      javassist.CannotCompileException: no such class: ArrayList

      is thrown.

      java.util.ArrayList al = new java.util.ArrayList()
      works fine.

      Thanks for hints & suggestions !

      code example:

      ClassPool pool = ClassPool.getDefault();
      CtClass cc = pool.getAndRename("myclass","myclass_cpy");

      // modify validate(...) method
      CtMethod meth = cc.getDeclaredMethod("validate");

      meth.insertAfter("{ ArrayList al = new ArrayList }"); // --> creates CannotCompileException although java.util.* exists as import in "myclass"
      meth.insertAfter("{ java.util.ArrayList al = new java.util.ArrayList }"); // --> works fine

      // write Class and create Instance
      Class rtc = cc.toClass();