harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r569151 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectInputStream.java main/java/java/io/ObjectStreamClass.java test/api/common/tests/api/java/io/ObjectInputStreamTest.java
Date Thu, 23 Aug 2007 21:28:44 GMT
Author: tellison
Date: Thu Aug 23 14:28:43 2007
New Revision: 569151

URL: http://svn.apache.org/viewvc?rev=569151&view=rev
Log:
Apply patch for HARMONY-4638 ([classlib][luni] ObjectStreamClass.lookup() incorrectly works)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/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?rev=569151&r1=569150&r2=569151&view=diff
==============================================================================
--- 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
Thu Aug 23 14:28:43 2007
@@ -1618,9 +1618,7 @@
         Integer oldHandle = descriptorHandle;
         descriptorHandle = Integer.valueOf(nextHandle());
         classDesc = readClassDescriptor();
-        if (descriptorHandle != null) {
-            registerObjectRead(classDesc, descriptorHandle, false);
-        }
+        registerObjectRead(classDesc, descriptorHandle, false);
         descriptorHandle = oldHandle;
         primitiveData = emptyStream;
         classDesc.setClass(resolveClass(classDesc));
@@ -1700,9 +1698,7 @@
         Integer oldHandle = descriptorHandle;
         descriptorHandle = Integer.valueOf(nextHandle());
         ObjectStreamClass newClassDesc = readClassDescriptor();
-        if (descriptorHandle != null) {
-            registerObjectRead(newClassDesc, descriptorHandle, unshared);
-        }
+        registerObjectRead(newClassDesc, descriptorHandle, unshared);
         descriptorHandle = oldHandle;
         primitiveData = emptyStream;
 
@@ -1792,7 +1788,6 @@
         descriptorHandle = (null == descriptorHandle ? Integer
                 .valueOf(nextHandle()) : descriptorHandle);
         registerObjectRead(newClassDesc, descriptorHandle, false);
-        descriptorHandle = null;
 
         readFieldDescriptors(newClassDesc);
         return newClassDesc;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java?rev=569151&r1=569150&r2=569151&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
Thu Aug 23 14:28:43 2007
@@ -232,6 +232,23 @@
             result.setFields(new ObjectStreamField[0]);
         }
 
+        // Copy all fields to loadFields - they should be read by default in
+        // ObjectInputStream.defaultReadObject() method
+        ObjectStreamField[] fields = result.getFields();
+    
+        if (fields != null) {
+            ObjectStreamField[] loadFields = new ObjectStreamField[fields.length];
+
+            for (int i = 0; i < fields.length; ++i) {
+                loadFields[i] = new ObjectStreamField(fields[i].getName(),
+                        fields[i].getType(), fields[i].isUnshared());
+
+                // resolve type string to init typeString field in ObjectStreamField
+                loadFields[i].getTypeString();
+            }
+            result.setLoadFields(loadFields);
+        }
+
         byte flags = 0;
         boolean externalizable = isExternalizable(cl);
         if (externalizable) {

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectInputStreamTest.java?rev=569151&r1=569150&r2=569151&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectInputStreamTest.java
Thu Aug 23 14:28:43 2007
@@ -32,12 +32,15 @@
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamClass;
 import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
 import java.io.Serializable;
 import java.io.SerializablePermission;
 import java.io.StreamCorruptedException;
 import java.security.Permission;
 import java.util.Arrays;
 import java.util.Hashtable;
+import java.util.HashMap;
 import java.util.Vector;
 
 import org.apache.harmony.testframework.serialization.SerializationTest;
@@ -711,8 +714,7 @@
 		Object obj = ois.readObject();
 		ois.close();
 		assertEquals(cls, obj);
-	}
-        
+	} 
 
 	// Regression Test for JIRA-2340
     public static class ObjectOutputStreamWithWriteDesc1 extends
@@ -921,6 +923,59 @@
         public void setCorrupt(boolean corrupt) {
             this.corrupt = corrupt;
         }
+    }
+
+    public static class ObjectIutputStreamWithReadDesc2 extends
+            ObjectInputStream {
+        private Class returnClass;
+
+        public ObjectIutputStreamWithReadDesc2(InputStream is, Class returnClass)
+                throws IOException {
+            super(is);
+            this.returnClass = returnClass;
+        }
+
+        public ObjectStreamClass readClassDescriptor() throws IOException,
+                ClassNotFoundException {
+            ObjectStreamClass osc = super.readClassDescriptor();
+
+            if (osc.getName().equals(returnClass.getName())) {
+                return ObjectStreamClass.lookup(returnClass);
+            }
+            return osc;
+        }
+    }
+
+    /*
+     * Testing classDescriptor replacement with the value generated by
+     * ObjectStreamClass.lookup() method.
+     * Regression test for HARMONY-4638
+     */
+    public void test_readClassDescriptor_1() throws IOException, ClassNotFoundException {
+        A a = new A();
+        a.name = "It's a test";
+        PipedOutputStream pout = new PipedOutputStream();
+        PipedInputStream pin = new PipedInputStream(pout);
+        ObjectOutputStream out = new ObjectOutputStream(pout);
+        ObjectInputStream in = new ObjectIutputStreamWithReadDesc2(pin, A.class);
+
+        // test single object
+        out.writeObject(a);
+        A a1 = (A) in.readObject();
+        assertEquals("Single case: incorrectly read the field of A", a.name, a1.name);
+
+        // test cyclic reference
+        HashMap m = new HashMap();
+        a = new A();
+        a.name = "It's a test 0";
+        a1 = new A();
+        a1.name = "It's a test 1";
+        m.put("0", a);
+        m.put("1", a1);
+        out.writeObject(m);
+        HashMap m1 = (HashMap) in.readObject();
+        assertEquals("Incorrectly read the field of A", a.name, ((A) m1.get("0")).name);
+        assertEquals("Incorrectly read the field of A1", a1.name, ((A) m1.get("1")).name);
     }
 
     public void test_registerValidation() throws Exception {



Mime
View raw message