harmony-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?view=rev&rev=479576
Log:
Apply patch for HARMONY-2249 ([classlib][luni]ObjectInputStream.readObject throws NullPointerException
while readClassDescriptor has been overriden)

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=479576&r1=479575&r2=479576
==============================================================================
--- 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 27 02:34:42 2006
@@ -1091,7 +1091,8 @@
     private void readFieldValues(Object obj, ObjectStreamClass classDesc)
             throws OptionalDataException, ClassNotFoundException, IOException {
         // Now we must read all fields and assign them to the receiver
-        ObjectStreamField[] fields = classDesc.getLoadFields();
+    	ObjectStreamField[] fields = classDesc.getLoadFields();
+    	fields = (null == fields ? new ObjectStreamField[] {} : fields);
         Class<?> declaringClass = classDesc.forClass();
         if (declaringClass == null && mustResolve) {
             throw new ClassNotFoundException(classDesc.getName());
@@ -1686,6 +1687,7 @@
         // Resolve the field signatures using the class loader of the
         // resolved class
         ObjectStreamField[] fields = newClassDesc.getLoadFields();
+        fields = (null == fields ? new ObjectStreamField[] {} : fields);
         ClassLoader loader = newClassDesc.forClass() == null ? callerClassLoader
                 : newClassDesc.forClass().getClassLoader();
         for (ObjectStreamField element : fields) {

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=479576&r1=479575&r2=479576
==============================================================================
--- 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 27 02:34:42 2006
@@ -27,6 +27,8 @@
 import java.io.NotActiveException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.OutputStream;
 import java.io.Serializable;
 import java.io.SerializablePermission;
 import java.io.StreamCorruptedException;
@@ -653,7 +655,57 @@
 		Test another = (Test) in.readObject();
 		in.close();
 		assertEquals(test, another);
-	}  
+	}
+    
+    //Regression Test for JIRA-2249
+    public static class ObjectOutputStreamWithWriteDesc extends
+            ObjectOutputStream {
+        public ObjectOutputStreamWithWriteDesc(OutputStream os)
+                throws IOException {
+            super(os);
+        }
+
+        public void writeClassDescriptor(ObjectStreamClass desc)
+                throws IOException {
+        }
+    }
+
+    public static class ObjectIutputStreamWithReadDesc extends
+            ObjectInputStream {
+        private Class returnClass;
+
+        public ObjectIutputStreamWithReadDesc(InputStream is, Class returnClass)
+                throws IOException {
+            super(is);
+            this.returnClass = returnClass;
+        }
+
+        public ObjectStreamClass readClassDescriptor() throws IOException,
+                ClassNotFoundException {
+            return ObjectStreamClass.lookup(returnClass);
+
+        }
+    }
+    
+    static class TestClassForSerialization implements Serializable {
+	}
+
+    public void test_ClassDescriptor() throws IOException,
+			ClassNotFoundException {
+
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ObjectOutputStreamWithWriteDesc oos = new ObjectOutputStreamWithWriteDesc(
+				baos);
+		oos.writeObject(String.class);
+		oos.close();
+		Class cls = TestClassForSerialization.class;
+		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+		ObjectIutputStreamWithReadDesc ois = new ObjectIutputStreamWithReadDesc(
+				bais, cls);
+		Object obj = ois.readObject();
+		ois.close();
+		assertEquals(cls, obj);
+	}
    
 
     /**



Mime
View raw message