0 Replies Latest reply on Oct 30, 2008 8:57 AM by Aleksander Kosicki

    Unexpected change of CtConstructor parameter type

    Aleksander Kosicki Newbie

      I've noticed strange CtConstructor's constructor behavior. The following code illustrates the problem:

      import javassist.ClassPool;
      import javassist.CtClass;
      import javassist.CtConstructor;
      
      public class Test {
       Test( Test t ){}
      
       public static void main(String[] args) throws Exception {
       ClassPool pool = ClassPool.getDefault();
      
       CtClass baseCtClass = pool.getCtClass( Test.class.getName() );
       CtClass childCtClass = pool.makeClass( Test.class.getName() + "$$Ex", baseCtClass );
      
       assert baseCtClass.getDeclaredConstructors().length == 1;
       assert baseCtClass.getDeclaredConstructors()[0].getParameterTypes().length == 1;
       assert baseCtClass.getDeclaredConstructors()[0].getParameterTypes()[0].equals( baseCtClass );
      
       assert childCtClass.getDeclaredConstructors().length == 0;
      
       CtConstructor childCtor = new CtConstructor( baseCtClass.getDeclaredConstructors()[0], childCtClass, null );
       childCtor.setBody( "{ super($$); }" );
       childCtClass.addConstructor( childCtor );
      
       assert childCtClass.getDeclaredConstructors().length == 1;
       assert childCtClass.getDeclaredConstructors()[0].getParameterTypes().length == 1;
       assert childCtClass.getDeclaredConstructors()[0].getParameterTypes()[0].equals( baseCtClass );
       //the last assert fails (at least using Sun's jdk 1.6 u 10 / javassist 3.9.0 )
       //for some reason ctor parameter type is Test$$Ex instead of Test
       }
      }
      


      Last program assertion fails. The CtConstructor parameter is changed from Test to the Test$$Ex. Is it done on purpose?

      Regards