harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r442534 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectOutputStream.java test/java/tests/api/java/io/ObjectOutputStreamTest.java
Date Tue, 12 Sep 2006 09:05:53 GMT
Author: pyang
Date: Tue Sep 12 02:05:53 2006
New Revision: 442534

URL: http://svn.apache.org/viewvc?view=rev&rev=442534
Log:
Patch applied for HARMONY-1429 (Stream-based replacement does not work in ObjectOutputStream)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java?view=diff&rev=442534&r1=442533&r2=442534
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
Tue Sep 12 02:05:53 2006
@@ -1824,9 +1824,6 @@
 	private Integer writeObjectInternal(Object object, boolean unshared,
 			boolean computeClassBasedReplacement,
 			boolean computeStreamReplacement) throws IOException {
-        if (object != null && !ObjectStreamClass.isSerializable(object.getClass()))
{
-            throw new NotSerializableException(object.getClass().getName());
-        }
 		if (object == null) {
 			writeNull();
 			return null;
@@ -1854,7 +1851,7 @@
 				return writeClassDesc((ObjectStreamClass) object, unshared);
 			}
 
-			if (computeClassBasedReplacement) {
+			if (ObjectStreamClass.isSerializable(object.getClass()) && computeClassBasedReplacement)
{
 				Object writeReplaceMethod = writeReplaceCache.get(objClass);
 				if (writeReplaceMethod != this) {
 					if (writeReplaceMethod == null) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java?view=diff&rev=442534&r1=442533&r2=442534
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
Tue Sep 12 02:05:53 2006
@@ -470,6 +470,21 @@
 		}
 	}
 
+    private static class ObjectOutputStreamWithReplace extends ObjectOutputStream {
+        public ObjectOutputStreamWithReplace(OutputStream out) throws IOException {
+            super(out);
+            enableReplaceObject(true);
+        }
+
+        protected Object replaceObject(Object obj) throws IOException {
+            if (obj instanceof NotSerializable) {
+                return new Long(10);
+            } else {
+                return obj;
+            }
+        }
+    }
+
 	protected static final String MODE_XLOAD = "xload";
 
 	protected static final String MODE_XDUMP = "xdump";
@@ -1151,5 +1166,22 @@
         } finally {
             oos.close();
         }
+    }
+
+    /**
+     * @tests java.io.ObjectOutputStream#replaceObject(java.lang.Object)
+     */
+    public void test_replaceObject() throws Exception {
+        //Regression for HARMONY-1429
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStreamWithReplace oos = new ObjectOutputStreamWithReplace(baos);
+
+        oos.writeObject(new NotSerializable());
+        oos.flush();
+        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
+        Object obj = ois.readObject();
+        oos.close();
+        ois.close();
+        assertTrue("replaceObject has not been called", (obj instanceof Long));
     }
 }



Mime
View raw message