5 Replies Latest reply on Jan 24, 2005 10:31 AM by Shigeru Chiba

    Bug in getDeclaringClass in 3.0RC1

    Howard Lovatt Newbie

      There is a bug in the getDeclaringClass method of CtClass when you try and get the declaring class of an anonymous inner class it throws FileNotFoundException. EG:

      package examples.javassisttests.declaringclasses;
      import javassist.*;
      public class Test {
      public static void main( final String[] notUsed ) throws NotFoundException {
      new Object() {}; // annonymous inner class
      final CtClass inner = ClassPool.getDefault().get( "examples.javassisttests.declaringclasses.Test$1" );
      System.out.println( "Inner class = " + inner.getName() );
      System.out.println( "Outer class (direct) = " + ClassPool.getDefault().get( "examples.javassisttests.declaringclasses.Test" ).getName() );
      System.out.println( "Outer class (from inner) = " + inner.getDeclaringClass().getName() );
      }
      }

      Produces:

      Inner class = examples.javassisttests.declaringclasses.Test$1
      Outer class (direct) = examples.javassisttests.declaringclasses.Test
      javassist.NotFoundException
      at javassist.ClassPool.get(ClassPool.java:295)
      at javassist.CtClassType.getDeclaringClass(CtClassType.java:412)
      at examples.javassisttests.declaringclasses.Test.main(Test.java:9)
      Exception in thread "main"