4 Replies Latest reply on Nov 4, 2004 11:31 AM by chiba

    Copying / Moving fabricated CtClass from one ClassPool to an

    hlship

      Here's my situation:

      I have two ClassPool instances, let's call them A and B.

      I create a new CtClass in ClassPool A. It has an arbitrary name, generated at runtime. I succesfully create my CtClass, and with the help of a custom class loader, instantiate an instance of the actual Class. Let's call that C1.

      Later, I want to create a different Class, Class C2, using ClassPool B.

      C2 has methods and fields of type C1.

      I get Javassist errors at this point:

      Caused by: org.apache.hivemind.ApplicationRuntimeException: Unable to add constructor to class $ServicePropertyProxy_feb5c6c94d_43: [source error] javassist.NotFoundException: $SingletonProxy_feb5c6c871_37

      That's because C1 ($SingletonProxy...) is unknown to the ClassPool B, which is trying to create Class C2 ($ServicePropertyProxy...).

      What I'm struggling with is a way to "tell" ClassPool B about a class fabrictaed using ClassPool A.

      I'd love some feedback; in the meantime I'm pursuing my own approach, where I have a subclass of ClassPool that I can "inject" with my CtClass instances from foriegn ClassPools.

        • 1. Re: Copying / Moving fabricated CtClass from one ClassPool t
          hlship

          BTW ... it's for Javassist 2.6.

          I have a solution that involves sharing the ClassPool. It seems to work. It does involve invoking the appendClassPath() method, which is not synchronized (I created a subclass of ClassPool that synchronized the method).

          I'm somewhat concerned about what will happen in a complex classloader environment when there are conflicts between some of the classes. Testing will tell.

          • 2. Re: Copying / Moving fabricated CtClass from one ClassPool t
            chiba

            Due to the problem you mentioned, I modified
            the ClassPool architecture; Javassist 3.0 allows
            cascading ClassPools as Java does ClassLoaders.
            You can tell a ClassPool (B) to delegate to the
            parent (A) if it does not find a class.

            • 3. Re: Copying / Moving fabricated CtClass from one ClassPool t
              hlship

              I actually reorganized my code and found a way to continue using 2.6. I share a single class pool, but do some interesting work with a customized delegating class loader.

              BTW ... I have to say that for many typical uses of Javassist, the wrapper services for it in HiveMind make it very, very easy. By typical use, I mean how Tapestry and HiveMind use Javassist: to create new classes at runtime (not modify existing classes). This is a small subset of Javassist, but a very useful one.

              I just queried in the dev forum ... when will try...finally be supported?

              • 4. Re: Copying / Moving fabricated CtClass from one ClassPool t
                chiba

                 

                I just queried in the dev forum ... when will try...finally be supported?


                I have just implemented try-finally and checked the code into the CVS.