1 Reply Latest reply on Jan 24, 2011 6:06 PM by Ragnar Rova

    getDeclaringClass throws error

    Ragnar Rova Newbie



      Why does the following testcase fail with IncompatibleClassChangeError ?


      package foo;
      import javassist.*;
      import org.junit.*;
      public class GetDeclaringClassTest {
          static class Foo {
              String bar;
          public void get_declaring_class_should_not_throw_error()
                  throws NotFoundException, CannotCompileException {
              ClassPool pool = ClassPool.getDefault();
              CtClass cc = pool.get(Foo.class.getName());
              cc.setName(Foo.class.getName() + "$BackRef");
              Class<?> klass = cc.toClass();
        • 1. getDeclaringClass throws error
          Ragnar Rova Newbie

          Error was


          java.lang.IncompatibleClassChangeError: foo.GetDeclaringClassTest and foo.GetDeclaringClassTest$Foo$BackRef disagree on InnerClasses attribute



          Is it because I have not modified the outer class? How can I create a copy of a inner class (and add one field) without getting this error?