1 Reply Latest reply on Jul 6, 2004 11:50 AM by chiba

    Javassist 3.0 - trouble accessing field from constructor

    nathanmeyers

      Hello from a new user...

      I've got a couple of instrumented classfiles - the classfiles were made reflective and are being loaded by JBoss's standard classloader. Their relationship is something like this (simplified, of course):

      public class A {
       private SomeClass x;
       public A() {
       getX().someMethod();
       }
       public SomeClass getX() {
       return x;
       }
      }
      
      public class B extends A {
      }


      I'm hitting a NullPointerException in the Metaobject class during construction of an instance of B. The call stack looks something like this:

       Metaobject.trapMethodcall()
       A._added_m$0()
       A.getX()
       A.<init>
       B.<init>
      


      The trapMethodcall() is throwing a NullPointerException because the methods[] array is not yet initialized - as we would expect during the constructor call. But this breaks the accessor.

      In case it's relevant, I didn't build the classfile by running javassist.reflect.Compiler, but I copied the compiler's logic - making the class reflective with Reflection.makeReflective() and Reflection.onLoad(), then writing the resulting classfiles.

      Any insights about what I'm doing wrong?