harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r572165 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectOutputStream.java main/java/org/apache/harmony/luni/util/ExternalMessages.properties test/api/common/tests/api/java/io/ObjectOutputStreamTest.java
Date Sun, 02 Sep 2007 21:28:14 GMT
Author: tellison
Date: Sun Sep  2 14:28:14 2007
New Revision: 572165

URL: http://svn.apache.org/viewvc?rev=572165&view=rev
Log:
Not allowed to change the serialization stream protocol version once data has been written.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/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?rev=572165&r1=572164&r2=572165&view=diff
==============================================================================
--- 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
Sun Sep  2 14:28:14 2007
@@ -22,6 +22,8 @@
 import java.lang.reflect.Proxy;
 import java.util.IdentityHashMap;
 
+import org.apache.harmony.luni.util.Msg;
+
 /**
  * An ObjectOutputStream can be used to save Java objects into a stream where
  * the objects can be loaded later with an ObjectInputStream. Primitive data
@@ -771,10 +773,14 @@
      *             If an IO error occurs
      */
     public void useProtocolVersion(int version) throws IOException {
+        if (!objectsWritten.isEmpty()) {
+            // KA028=Cannot set protocol version when stream in use
+            throw new IllegalStateException(Msg.getString("KA028")); //$NON-NLS-1$
+        }
         if (version != ObjectStreamConstants.PROTOCOL_VERSION_1
                 && version != ObjectStreamConstants.PROTOCOL_VERSION_2) {
-            throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg
-                    .getString("K00b3", version)); //$NON-NLS-1$
+            // K00b3=Unknown protocol\: {0}
+            throw new IllegalArgumentException(Msg.getString("K00b3", version)); //$NON-NLS-1$
         }
         protocolVersion = version;
     }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties?rev=572165&r1=572164&r2=572165&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
Sun Sep  2 14:28:14 2007
@@ -320,3 +320,4 @@
 KA025=Method has not been implemented
 KA026=JAR entry {0} not found in {1}
 KA027=Inputstream of the JarURLConnection has been closed
+KA028=Cannot set protocol version when stream in use

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectOutputStreamTest.java?rev=572165&r1=572164&r2=572165&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectOutputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectOutputStreamTest.java
Sun Sep  2 14:28:14 2007
@@ -30,6 +30,7 @@
 import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamClass;
+import java.io.ObjectStreamConstants;
 import java.io.ObjectStreamException;
 import java.io.ObjectStreamField;
 import java.io.OutputStream;
@@ -763,6 +764,16 @@
         assertTrue(
                 "Cannot read/write PROTOCAL_VERSION_1 Externalizable objects: "
                         + t2.getValue(), t1.getValue().equals(t2.getValue()));
+
+        // Cannot set protocol version when stream in-flight
+        ObjectOutputStream out = new ObjectOutputStream(new ByteArrayOutputStream());
+        out.writeObject("hello world");
+        try {
+            out.useProtocolVersion(ObjectStreamConstants.PROTOCOL_VERSION_1);
+            fail("Expected IllegalStateException");
+        } catch (IllegalStateException e) {
+            // Expected
+        }
     }
 
 	/**



Mime
View raw message