harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r927791 - in /harmony/enhanced/trunk/classlib/modules/luni/src: main/java/java/io/EmulatedFieldsForDumping.java main/java/java/io/ObjectOutputStream.java test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java
Date Fri, 26 Mar 2010 12:18:54 GMT
Author: odeakin
Date: Fri Mar 26 12:18:54 2010
New Revision: 927791

URL: http://svn.apache.org/viewvc?rev=927791&view=rev
Log:
Commit fix and regression test for HARMONY-6483 ([classlib][luni] No IllegalArgumentException
thrown by PutField.write() when writing to the wrong stream)

Modified:
    harmony/enhanced/trunk/classlib/modules/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
    harmony/enhanced/trunk/classlib/modules/luni/src/main/java/java/io/ObjectOutputStream.java
    harmony/enhanced/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java

Modified: harmony/enhanced/trunk/classlib/modules/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/trunk/classlib/modules/luni/src/main/java/java/io/EmulatedFieldsForDumping.java?rev=927791&r1=927790&r2=927791&view=diff
==============================================================================
--- harmony/enhanced/trunk/classlib/modules/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
(original)
+++ harmony/enhanced/trunk/classlib/modules/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
Fri Mar 26 12:18:54 2010
@@ -31,6 +31,9 @@ class EmulatedFieldsForDumping extends O
     // The actual representation, with a more powerful API (set&get)
     private EmulatedFields emulatedFields;
 
+    // Record the ObjectOutputStream that created this PutField for checking in the write
method
+    private final ObjectOutputStream oos;
+
     /**
      * Constructs a new instance of EmulatedFieldsForDumping.
      * 
@@ -38,10 +41,11 @@ class EmulatedFieldsForDumping extends O
      *            a ObjectStreamClass, which describe the fields to be emulated
      *            (names, types, etc).
      */
-    EmulatedFieldsForDumping(ObjectStreamClass streamClass) {
+    EmulatedFieldsForDumping(ObjectOutputStream oos, ObjectStreamClass streamClass) {
         super();
         emulatedFields = new EmulatedFields(streamClass.fields(),
                 (ObjectStreamField[]) null);
+        this.oos = oos;
     }
 
     /**
@@ -193,6 +197,10 @@ class EmulatedFieldsForDumping extends O
     @Override
     @Deprecated
     public void write(ObjectOutput output) throws IOException {
+        if (!output.equals(oos)) {
+            throw new IllegalArgumentException("Attempting to write to a stream that did
not create this PutField");
+        }
+
         EmulatedFields.ObjectSlot[] slots = emulatedFields.slots();
         for (int i = 0; i < slots.length; i++) {
             EmulatedFields.ObjectSlot slot = slots[i];

Modified: harmony/enhanced/trunk/classlib/modules/luni/src/main/java/java/io/ObjectOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/trunk/classlib/modules/luni/src/main/java/java/io/ObjectOutputStream.java?rev=927791&r1=927790&r2=927791&view=diff
==============================================================================
--- harmony/enhanced/trunk/classlib/modules/luni/src/main/java/java/io/ObjectOutputStream.java
(original)
+++ harmony/enhanced/trunk/classlib/modules/luni/src/main/java/java/io/ObjectOutputStream.java
Fri Mar 26 12:18:54 2010
@@ -388,7 +388,7 @@ public class ObjectOutputStream extends 
      * @see #writeFieldValues(EmulatedFieldsForDumping)
      */
     private void computePutField() {
-        currentPutField = new EmulatedFieldsForDumping(currentClass);
+        currentPutField = new EmulatedFieldsForDumping(this, currentClass);
     }
 
     /**

Modified: harmony/enhanced/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java?rev=927791&r1=927790&r2=927791&view=diff
==============================================================================
--- harmony/enhanced/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java
(original)
+++ harmony/enhanced/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java
Fri Mar 26 12:18:54 2010
@@ -1361,4 +1361,23 @@ public class ObjectOutputStreamTest exte
         assertEquals("3rd replaceObject worked incorrectly",
                 ObjectStreamClass.class, obj3.getClass());
     }
+
+    public void test_putFieldWrite() throws Exception {
+        // Regression test for HARMONY-6483
+        ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream());
+        try {
+            oos.writeObject(new OutputObject());
+            fail("Should throw an IllegalArgumentException");
+        } catch (IllegalArgumentException iae) {
+            // Expected
+        }
+    }
+
+    private static class OutputObject implements Serializable {
+        private void writeObject(ObjectOutputStream oos) throws IOException {
+            ObjectOutputStream oos2 = new ObjectOutputStream(new ByteArrayOutputStream());
+            ObjectOutputStream.PutField putField = oos.putFields();
+            putField.write(oos2);
+        }
+    }
 }



Mime
View raw message