[jboss-user] [JBoss Microcontainer Development] - Issues using Javassist TypeInfoFactory in other projects

Kabir Khan do-not-reply at jboss.com
Tue Mar 30 13:11:45 EDT 2010


Kabir Khan [http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the discussion

"Issues using Javassist TypeInfoFactory in other projects"

To view the discussion, visit: http://community.jboss.org/message/534708#534708

--------------------------------------------------------------
> 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
[http://community.jboss.org/message/534708#534708]

Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2115]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100330/440a8a4b/attachment.html 


More information about the jboss-user mailing list