harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r512270 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectOutputStream.java test/java/tests/api/java/io/ObjectOutputStreamTest.java
Date Tue, 27 Feb 2007 15:05:15 GMT
Author: ayza
Date: Tue Feb 27 07:05:01 2007
New Revision: 512270

URL: http://svn.apache.org/viewvc?view=rev&rev=512270
Log:
Applying patch from HARMONY-3158 ([classlib][luni]ObjectOutputStream.replaceObject fails when
serializable object is Class or interface)

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=512270&r1=512269&r2=512270
==============================================================================
--- 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 Feb 27 07:05:01 2007
@@ -1926,6 +1926,16 @@
 
             // We get here if stream-based replacement produced the same object
 
+            // 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);
+            }
+
             // Is it a String ? (instanceof, but == is faster)
             if (objClass == ObjectStreamClass.STRINGCLASS) {
                 return writeNewString((String) object, unshared);

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=512270&r1=512269&r2=512270
==============================================================================
--- 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 Feb 27 07:05:01 2007
@@ -498,6 +498,8 @@
         protected Object replaceObject(Object obj) throws IOException {
             if (obj instanceof NotSerializable) {
                 return new Long(10);
+            } else if (obj instanceof Integer) {
+                return new Long(((Integer) obj).longValue());
             } else {
                 return obj;
             }
@@ -1253,5 +1255,24 @@
 		oos.close();
 		ois.close();
 		assertTrue("replaceObject has not been called", (obj instanceof Long));
+
+        // Regression for HARMONY-3158
+        baos = new ByteArrayOutputStream();
+        oos = new ObjectOutputStreamWithReplace(baos);
+
+        oos.writeObject(new Integer(99));
+        oos.writeObject(Integer.class);
+        oos.writeObject(ObjectStreamClass.lookup(Integer.class));
+        oos.flush();
+
+        ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
+        Object obj1 = ois.readObject();
+        Object obj2 = ois.readObject();
+        Object obj3 = ois.readObject();
+        oos.close();
+        ois.close();
+        assertTrue("1st replaceObject worked incorrectly", (obj1 instanceof Long) &&
(((Long) obj1).longValue() == 99));
+        assertEquals("2nd replaceObject worked incorrectly", obj2, Integer.class);
+        assertEquals("3rd replaceObject worked incorrectly", obj3.getClass(), ObjectStreamClass.class);
 	}
 }



Mime
View raw message