You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by lv...@apache.org on 2010/02/08 15:00:16 UTC

svn commit: r907658 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java

Author: lvjing
Date: Mon Feb  8 14:00:16 2010
New Revision: 907658

URL: http://svn.apache.org/viewvc?rev=907658&view=rev
Log:
Apply patch for HARMONY-6439 [classlib][luni] NullPointerException thrown in certain Serialization cases, refine the testcase

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java?rev=907658&r1=907657&r2=907658&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java Mon Feb  8 14:00:16 2010
@@ -224,7 +224,9 @@
     }
     
 
-    /* Write/serialize and read/de-serialize an object. */
+    /**
+     * Write/serialize and read/de-serialize an object with primitive field
+     */ 
     public void test_ObjectWithPrimitiveField()
         throws IOException, ClassNotFoundException {
 
@@ -234,8 +236,7 @@
         final byte[] bytes = baos.toByteArray();
         final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
         final MyObjectInputStream ois = new MyObjectInputStream(bais);
-        /* NullPointerException is thrown by the readObject call below. */
-        System.out.println("start");
+        // NullPointerException is thrown by the readObject call below. 
         ois.readObject();
     }
 
@@ -346,19 +347,20 @@
 }
 
 
-/* Primitive fields are necessary to cause the NullPointerException. */
+// Primitive fields are necessary to cause the NullPointerException. 
 class MockClass implements Serializable {
-    String field1 = "field1";
-    String field2 = "field2";
-    int field3 = 333;
-    int field4 = 444;
-    String field5 = "field5";
+    String str1 = "string 1";
+    String str2 = "string 2";
+    int int1 = 1;
+    int int2 = 2;
+    String str3 = "string 3";
 }
 
 
-/* Overrides writeClassDescriptor to store ObjectStreamClass in map. */
+// Overrides writeClassDescriptor to store ObjectStreamClass in map. 
 class MyObjectOutputStream extends ObjectOutputStream {
 
+    // record the only ObjectStreamClass
     static ObjectStreamClass descs;
     
     MyObjectOutputStream(OutputStream out)
@@ -370,31 +372,24 @@
     protected void writeClassDescriptor(ObjectStreamClass desc)
         throws IOException {
         descs = desc;
-        final int id = 1;
-        /* Write ID of ObjectStreamClass. */
-        writeInt(id);
+        // Write a int
+        writeInt(1);
     }
 }
 
-/* Overrides readClassDescriptor to get ObjectStreamClass from map. */
+// Overrides readClassDescriptor to get ObjectStreamClass from map.
 class MyObjectInputStream extends ObjectInputStream {
 
     MyObjectInputStream(InputStream in)
         throws IOException {
-
         super(in);
     }
 
     @Override
     protected ObjectStreamClass readClassDescriptor()
         throws IOException, ClassNotFoundException {
-
-        /* Read the ID and get the ObjectStreamClass from a map. */
+        // Read a integer and get the only ObjectStreamClass for the test
         final int id = readInt();
-        final ObjectStreamClass desc = MyObjectOutputStream.descs;
-        if (desc == null) {
-            throw new ClassNotFoundException("id not found: " + id);
-        }
-        return desc;
+        return MyObjectOutputStream.descs;
     }
 }