[jboss-cvs] JBoss Messaging SVN: r8480 - branches/Branch_1_4/src/main/org/jboss/messaging/util.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 21 09:14:49 EST 2011


Author: gaohoward
Date: 2011-12-21 09:14:48 -0500 (Wed, 21 Dec 2011)
New Revision: 8480

Modified:
   branches/Branch_1_4/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java
Log:
JBMESSAGING-1909


Modified: branches/Branch_1_4/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java	2011-11-11 15:16:01 UTC (rev 8479)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java	2011-12-21 14:14:48 UTC (rev 8480)
@@ -26,6 +26,8 @@
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectStreamClass;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
 
 /**
  * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
@@ -79,6 +81,55 @@
       }
    }
 
+   //https://issues.jboss.org/browse/JBMESSAGING-1909
+   //Using Tccl to load interface class first.
+   @Override
+   protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException
+   {
+      ClassLoader loader = SecurityActions.getTCL();
+      
+      ClassLoader nonPublicLoader = null;
+      boolean hasNonPublicInterface = false;
+
+      // define proxy in class loader of non-public interface(s), if any
+      Class[] classObjs = new Class[interfaces.length];
+      
+      try
+      {
+         for (int i = 0; i < interfaces.length; i++)
+         {
+            Class cl = Class.forName(interfaces[i], false, loader);
+            if ((cl.getModifiers() & Modifier.PUBLIC) == 0)
+            {
+               if (hasNonPublicInterface)
+               {
+                  if (nonPublicLoader != cl.getClassLoader())
+                  {
+                     throw new IllegalAccessError("conflicting non-public interface class loaders");
+                  }
+               }
+               else
+               {
+                  nonPublicLoader = cl.getClassLoader();
+                  hasNonPublicInterface = true;
+               }
+            }
+            classObjs[i] = cl;
+         }
+         try
+         {
+            return Proxy.getProxyClass(hasNonPublicInterface ? nonPublicLoader : loader, classObjs);
+         }
+         catch (IllegalArgumentException e)
+         {
+            throw new ClassNotFoundException(null, e);
+         }
+      }
+      catch (ClassNotFoundException cnfe)
+      {
+         return super.resolveProxyClass(interfaces);
+      }
+   }
    // Private --------------------------------------------------------------------------------------
 
    // Inner classes --------------------------------------------------------------------------------



More information about the jboss-cvs-commits mailing list