harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r477748 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectOutputStream.java test/java/tests/api/java/io/ObjectOutputStreamTest.java
Date Tue, 21 Nov 2006 17:03:27 GMT
Author: pyang
Date: Tue Nov 21 09:03:26 2006
New Revision: 477748

URL: http://svn.apache.org/viewvc?view=rev&rev=477748
Log:
Apply patch for HARMONY-2239 ( [classlib][luni]ObjectOutputStream fails to call ReplaceObject
while the serialized class is int.class)

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

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java?view=diff&rev=477748&r1=477747&r2=477748
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
Tue Nov 21 09:03:26 2006
@@ -1843,14 +1843,15 @@
 		nestedLevels++;
 		try {
 
-			// Is it a Class ?
-			if (objClass == ObjectStreamClass.CLASSCLASS) {
-				return writeNewClass((Class) object, unshared);
-			}
-
-			// Is it an ObjectStreamClass ?
-			if (objClass == ObjectStreamClass.OBJECTSTREAMCLASSCLASS) {
-				return writeClassDesc((ObjectStreamClass) object, unshared);
+			if (!(enableReplace && computeStreamReplacement)) {
+				// Is it a Class ?
+				if (objClass == ObjectStreamClass.CLASSCLASS) {
+					return writeNewClass((Class) object, unshared);
+				}
+				// Is it an ObjectStreamClass ?
+				if (objClass == ObjectStreamClass.OBJECTSTREAMCLASSCLASS) {
+					return writeClassDesc((ObjectStreamClass) object, unshared);
+				}
 			}
 
 			if (ObjectStreamClass.isSerializable(object.getClass()) && computeClassBasedReplacement)
{

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java?view=diff&rev=477748&r1=477747&r2=477748
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
Tue Nov 21 09:03:26 2006
@@ -29,6 +29,7 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
 import java.io.ObjectStreamException;
 import java.io.ObjectStreamField;
 import java.io.OutputStream;
@@ -454,6 +455,22 @@
 			return new Integer(42);
 		}
 	}
+	
+	private static class WriteReplaceObject implements Serializable {
+        private Object replaceObject;
+
+        private static enum Color {
+            red, blue, green
+        };
+
+        public WriteReplaceObject(Object o) {
+            replaceObject = o;
+        }
+
+        protected Object writeReplace() throws ObjectStreamException {
+            return replaceObject;
+        }
+    }
 
 	private static class ExternalizableWithReplace implements Externalizable {
 		private int foo;
@@ -486,6 +503,19 @@
             }
         }
     }
+        
+    private static class ObjectOutputStreamWithReplace2 extends
+            ObjectOutputStream {
+        public ObjectOutputStreamWithReplace2(OutputStream out)
+                throws IOException {
+            super(out);
+            enableReplaceObject(true);
+        }
+
+        protected Object replaceObject(Object obj) throws IOException {
+            return new Long(10);
+        }
+    }
 
 	protected static final String MODE_XLOAD = "xload";
 
@@ -1185,5 +1215,43 @@
         oos.close();
         ois.close();
         assertTrue("replaceObject has not been called", (obj instanceof Long));
-    }
+
+		//Regression for HARMONY-2239
+		Object replaceObject = int.class;
+		baos = new ByteArrayOutputStream();
+		ObjectOutputStreamWithReplace2 oos2 = new ObjectOutputStreamWithReplace2(
+				baos);
+		oos2.writeObject(new WriteReplaceObject(replaceObject));
+		oos2.flush();
+		ois = new ObjectInputStream(
+				new ByteArrayInputStream(baos.toByteArray()));
+		obj = ois.readObject();
+		oos.close();
+		ois.close();
+		assertTrue("replaceObject has not been called", (obj instanceof Long));
+
+		replaceObject = ObjectStreamClass.lookup(Integer.class);
+		baos = new ByteArrayOutputStream();
+		oos2 = new ObjectOutputStreamWithReplace2(baos);
+		oos2.writeObject(new WriteReplaceObject(replaceObject));
+		oos2.flush();
+		ois = new ObjectInputStream(
+				new ByteArrayInputStream(baos.toByteArray()));
+		obj = ois.readObject();
+		oos.close();
+		ois.close();
+		assertTrue("replaceObject has not been called", (obj instanceof Long));
+
+		replaceObject = WriteReplaceObject.Color.red;
+		baos = new ByteArrayOutputStream();
+		oos2 = new ObjectOutputStreamWithReplace2(baos);
+		oos2.writeObject(new WriteReplaceObject(replaceObject));
+		oos2.flush();
+		ois = new ObjectInputStream(
+				new ByteArrayInputStream(baos.toByteArray()));
+		obj = ois.readObject();
+		oos.close();
+		ois.close();
+		assertTrue("replaceObject has not been called", (obj instanceof Long));
+	}
 }



Mime
View raw message