Community

Issues using Javassist TypeInfoFactory in other projects

reply from Kabir Khan in JBoss Microcontainer Development - View the full discussion

Another issue is that dynamically created classes are not found in the classpools.

 

Dynamic proxies are not found at all:

0 DEBUG [JDKLazyInstantiationTestCase] ==== setUp org.jboss.test.kernel.lazy.test.JDKLazyInstantiationTestCase ====

5 DEBUG [JDKLazyInstantiationTestCase] ==== Starting testLazy ====

20 DEBUG [KernelFactory] Starting JBoss Kernel construction...

53 WARN  [PropertyConfiguration] Factory: org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory@4393722c

466 DEBUG [KernelFactory] Completed JBoss Kernel construction.  Duration: 446 milliseconds

568 ERROR [AbstractKernelController] Error installing to Instantiated: name=beanProxy state=Described

java.lang.RuntimeException: Class not found: $Proxy0

at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.get(JavassistTypeInfoFactoryImpl.java:311)

at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.getTypeInfo(JavassistTypeInfoFactoryImpl.java:519)

at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory.getTypeInfo(JavassistTypeInfoFactory.java:51)

at org.jboss.classadapter.plugins.BasicClassAdapterFactory.getClassAdapter(BasicClassAdapterFactory.java:54)

 

 

Neither are the javassist ProxyFactory proxies, since they just define the class in the classloader with no way to find them from the pools:

0 DEBUG [JavassistLazyInstantiationTestCase] ==== setUp org.jboss.test.kernel.lazy.test.JavassistLazyInstantiationTestCase ====

3 DEBUG [JavassistLazyInstantiationTestCase] ==== Starting testLazy ====

18 DEBUG [KernelFactory] Starting JBoss Kernel construction...

47 WARN  [PropertyConfiguration] Factory: org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory@4393722c

514 DEBUG [KernelFactory] Completed JBoss Kernel construction.  Duration: 496 milliseconds

618 ERROR [AbstractKernelController] Error installing to Instantiated: name=beanProxy state=Described

java.lang.RuntimeException: Class not found: org.jboss.test.kernel.lazy.support.IRare_$$_javassist_0

at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.get(JavassistTypeInfoFactoryImpl.java:311)

at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.getTypeInfo(JavassistTypeInfoFactoryImpl.java:519)

at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory.getTypeInfo(JavassistTypeInfoFactory.java:51)

at org.jboss.classadapter.plugins.BasicClassAdapterFactory.getClassAdapter(BasicClassAdapterFactory.java:54)

 

In AOP what we did was to write the class bytes to the in memory vfs location from the aop classpools, so that when trying to look up the CtClass later there is a resource path for the class bytes:

         URL outputURL = new URL(tempURL.toString() + "/" + classFileName);
         //Write the classfile to the temporary url
         synchronized (tmplock)
         {
            if (trace) logger.trace(this + " " + pool + ".toClass() myloader:" + myloader + " writing bytes to " + tempURL);
            ByteArrayOutputStream byteout = new ByteArrayOutputStream();
            BufferedOutputStream out = new BufferedOutputStream(byteout);
            out.write(cc.toBytecode());
            out.flush();
            out.close();
 
            byte[] classBytes = byteout.toByteArray();
            MemoryContextFactory factory = MemoryContextFactory.getInstance();
            factory.putFile(outputURL, classBytes);

 

Going to check with Chiba, but I'll see if I can modify javassist to allow ProxyFactory and ProxyFactoryHelper to accept an interface like

 

interface ByteRecorder{
   void writeBytes(String classname, byte[]) throws IOException
}

 

 

 

Reply to this message by going to Community

Start a new discussion in JBoss Microcontainer Development at Community