Bug 22041

Summary: Loading DynamicProxys from session
Product: Tomcat 4 Reporter: Martin Harm <martin.harm.42>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 4.1.18   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Martin Harm 2003-08-01 07:46:48 UTC
If you got a DynamicProxy inside the session, catalina fails to load this 
object.




Suggested fix: (tested just a little bit, not realy)


in: org.apache.catalina.util.CustomObjectInputStream 


overwrite the method 


protected Class resolveProxyClass(String[] interfaces)


with the implementation of java.io.ObjectInputStream except


the first line 


ClassLoader latestLoader = classLoader; 


  // instead of ClassLoader latestLoader = latestUserDefinedLoader();




this seams to work..
Comment 1 Mark Thomas 2004-06-16 19:50:45 UTC
I'd prefer something along the lines of the patch below. Could you test this 
(or attach a simple test case to this bug report). If it works, I'll commit it.

Index: catalina/src/share/org/apache/catalina/util/CustomObjectInputStream.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-
catalina/catalina/src/share/org/apache/catalina/util/Cu
stomObjectInputStream.java,v
retrieving revision 1.3
diff -u -r1.3 CustomObjectInputStream.java
--- catalina/src/share/org/apache/catalina/util/CustomObjectInputStream.java
27 Feb 2004 14:58:50 -0000      1.3
+++ catalina/src/share/org/apache/catalina/util/CustomObjectInputStream.java
16 May 2004 13:35:18 -0000
@@ -72,5 +72,27 @@
         return Class.forName(classDesc.getName(), false, classLoader);
     }

+    /**
+     * Return a proxy class that implements the interfaces named in a proxy
+     * class descriptor. Do this using the class loader assigned to this
+     * Context.
+     */
+    protected Class resolveProxyClass(String[] interfaces)
+        throws IOException, ClassNotFoundException {
+
+        ClassLoader originalClassLoader =
+            Thread.currentThread().getContextClassLoader();
+
+        // Set thread to use context class loader
+        Thread.currentThread().setContextClassLoader(classLoader);
+
+        // Use super class to do all the real work
+        Class clazz = super.resolveProxyClass(interfaces);
+
+        // Swap back to original class loader
+        Thread.currentThread().setContextClassLoader(originalClassLoader);
+
+        return clazz;
+    }

 } 
Comment 2 Mark Thomas 2005-03-11 00:56:28 UTC
My sugested patch above doesn't work. However, I have committed an alternative
patch that does.

The patch was also ported to TC5.5.x