commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1080833 - in /commons/proper/io/trunk/src: main/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java
Date Sat, 12 Mar 2011 01:13:38 GMT
Author: niallp
Date: Sat Mar 12 01:13:38 2011
New Revision: 1080833

URL: http://svn.apache.org/viewvc?rev=1080833&view=rev
Log:
IO-260 Fix ClassLoaderObjectInputStream does not handle Proxy classes - thanks to John Carrino

Modified:
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java?rev=1080833&r1=1080832&r2=1080833&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java
Sat Mar 12 01:13:38 2011
@@ -21,6 +21,7 @@ import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectStreamClass;
 import java.io.StreamCorruptedException;
+import java.lang.reflect.Proxy;
 
 /**
  * A special ObjectInputStream that loads a class based on a specified
@@ -75,4 +76,27 @@ public class ClassLoaderObjectInputStrea
             return super.resolveClass(objectStreamClass);
         }
     }
+
+    /**
+     * Create a proxy class that implements the specified interfaces using
+     * the specified ClassLoader or the super ClassLoader.
+     *
+     * @param interfaces the interfaces to implemnt
+     * @return the class
+     * @see java.io.ObjectInputStream#resolveProxyClass(java.lang.String[])
+     */
+    @Override
+    protected Class<?> resolveProxyClass(String[] interfaces) throws IOException,
+            ClassNotFoundException {
+        Class<?>[] interfaceClasses = new Class[interfaces.length];
+        for (int i = 0; i < interfaces.length; i++) {
+            interfaceClasses[i] = Class.forName(interfaces[i], false, classLoader);
+        }
+        try {
+            return Proxy.getProxyClass(classLoader, interfaceClasses);
+        } catch (IllegalArgumentException e) {
+            return super.resolveProxyClass(interfaces);
+        }
+    }
+    
 }

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java?rev=1080833&r1=1080832&r2=1080833&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java
Sat Mar 12 01:13:38 2011
@@ -54,5 +54,19 @@ public class ClassLoaderObjectInputStrea
 
         assertTrue( !result.booleanValue() );
     }
+
+    public void testResolveProxyClass() throws Exception {
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject( Boolean.FALSE );
+        InputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+        ClassLoaderObjectInputStream clois = 
+            new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais);
+        String[] interfaces = new String[] { Comparable.class.getName() };
+        Class<?> result = clois.resolveProxyClass(interfaces);
+        assertTrue("Assignable", Comparable.class.isAssignableFrom(result));
+    }
     
 }



Mime
View raw message