Community

Issues using Javassist TypeInfoFactory in other projects

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

Kabir Khan wrote:

 

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

 

Rather than all the fancy BytecodeRecorder stuff, I am simply delegating to the IntrospectionTypeInfoFactory if the class can not be found in the classpool:

 

 

[kabir ~/sourcecontrol/jboss-reflect/trunk/jboss-reflect]
$svn diff
Index: src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
===================================================================
--- src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java     (revision 103127)
+++ src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java     (working copy)
@@ -49,6 +49,7 @@
 import org.jboss.reflect.plugins.AnnotationValueImpl;
 import org.jboss.reflect.plugins.EnumConstantInfoImpl;
 import org.jboss.reflect.plugins.GenericsUtil;
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
 import org.jboss.reflect.plugins.javassist.classpool.ClassPoolFactory;
 import org.jboss.reflect.plugins.javassist.classpool.DefaultClassPoolFactory;
 import org.jboss.reflect.spi.AnnotationInfo;
@@ -284,11 +285,33 @@
       }
       catch(NotFoundException nfe)
       {
-         throw new ClassNotFoundException(nfe.getMessage());
+         return delegateToIntrospectionImplementation(cl, name);
       }
    }
    
    /**
+    * Proxies, whether
+    * <ul>
+    * <li>JDK dynamic proxies</li>
+    * <li>javassist ProxyFactory proxies - created by calling ClassLoader.defineClass()</li>
+    * </ul> 
+    * are not visible to the javassist classpools, and neither will classes generated by cglib or other
+    * frameworks, so try to load up the class from the reflect implementation.
+    * 
+    * @param cl the classloader
+    * @param name the name of the class
+    * @return the info
+    * @throws ClassNotFoundException when the class cannot be found
+    */
+   private TypeInfo delegateToIntrospectionImplementation(ClassLoader cl, String name) throws ClassNotFoundException
+   {
+      //Check the class has been loaded
+      cl.loadClass(name);
+      IntrospectionTypeInfoFactory factory = new IntrospectionTypeInfoFactory();
+      return factory.getTypeInfo(name, cl);
+   }
+   
+   /**

Reply to this message by going to Community

Start a new discussion in JBoss Microcontainer Development at Community