harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r477132 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectInputStream.java test/java/tests/api/java/io/ObjectInputStreamTest.java
Date Mon, 20 Nov 2006 10:15:19 GMT
Author: liangyx
Date: Mon Nov 20 02:15:18 2006
New Revision: 477132

URL: http://svn.apache.org/viewvc?view=rev&rev=477132
Log:
Apply patch for HARMONY-2192 ([classlib][ObjectStreamInputStream]Fails to deserialze an object
created by cglib)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java?view=diff&rev=477132&r1=477131&r2=477132
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
Mon Nov 20 02:15:18 2006
@@ -107,6 +107,19 @@
 
     // cache for readResolve methods
     private IdentityHashMap<Class<?>, Object> readResolveCache;
+    
+    private static final Hashtable<String, Class> PRIMITIVE_CLASSES = new Hashtable<String,Class>();
+    
+    static {
+		PRIMITIVE_CLASSES.put("byte", byte.class);
+		PRIMITIVE_CLASSES.put("short", short.class);
+		PRIMITIVE_CLASSES.put("int", int.class);
+		PRIMITIVE_CLASSES.put("long", long.class);
+		PRIMITIVE_CLASSES.put("boolean", boolean.class);
+		PRIMITIVE_CLASSES.put("char", char.class);
+		PRIMITIVE_CLASSES.put("float", float.class);
+		PRIMITIVE_CLASSES.put("double", double.class);
+	}
 
     // Internal type used to keep track of validators & corresponding priority
     class InputValidationDesc {
@@ -2350,11 +2363,18 @@
      *             If the corresponding class cannot be found.
      */
     protected Class<?> resolveClass(ObjectStreamClass osClass)
-            throws IOException, ClassNotFoundException {
-        // Use the first non-null ClassLoader on the stack. If null, use the
-        // system class loader
-        return Class.forName(osClass.getName(), true, callerClassLoader);
-    }
+			throws IOException, ClassNotFoundException {		
+		String className = osClass.getName();
+		//if it is primitive class, for example, long.class
+		Class cls = PRIMITIVE_CLASSES.get(className);
+		if (null == cls) {
+			//not primitive class
+            //Use the first non-null ClassLoader on the stack. If null, use the
+			// system class loader
+			return cls = Class.forName(className, true, callerClassLoader);
+		}
+		return cls;
+	}
 
     /**
      * If <code>enableResolveObject()</code> was activated, computes the

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java?view=diff&rev=477132&r1=477131&r2=477132
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
Mon Nov 20 02:15:18 2006
@@ -19,6 +19,9 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.NotActiveException;
@@ -28,6 +31,7 @@
 import java.io.SerializablePermission;
 import java.io.StreamCorruptedException;
 import java.security.Permission;
+import java.util.Arrays;
 import java.util.Hashtable;
 import java.util.Vector;
 
@@ -634,6 +638,23 @@
             fail("NullPointerException expected");
         } catch (NullPointerException e) {}
     }
+    
+    // Regression Test for JIRA 2192
+	public void test_readObject_withPrimitiveClass() throws Exception {
+		File file = new File("test.ser");
+		file.deleteOnExit();
+		Test test = new Test();
+		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
+				file));
+		out.writeObject(test);
+		out.close();
+
+		ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
+		Test another = (Test) in.readObject();
+		in.close();
+		assertEquals(test, another);
+	}  
+   
 
     /**
      * Sets up the fixture, for example, open a network connection. This method
@@ -643,4 +664,19 @@
         super.setUp();
         oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
     }
+}
+
+
+class Test implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	Class classes[] = new Class[] { byte.class, short.class, int.class,
+			long.class, boolean.class, char.class, float.class, double.class };
+
+	public boolean equals(Object o) {
+		if (!(o instanceof Test)) {
+			return false;
+		}
+		return Arrays.equals(classes, ((Test) o).classes);
+	}
 }



Mime
View raw message