From commits-return-43065-apmail-harmony-commits-archive=harmony.apache.org@harmony.apache.org Sun Sep 02 21:28:49 2007 Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 53358 invoked from network); 2 Sep 2007 21:28:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Sep 2007 21:28:49 -0000 Received: (qmail 8068 invoked by uid 500); 2 Sep 2007 21:28:34 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 8045 invoked by uid 500); 2 Sep 2007 21:28:34 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 8029 invoked by uid 99); 2 Sep 2007 21:28:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Sep 2007 14:28:34 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Sep 2007 21:28:36 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6B6861A9832; Sun, 2 Sep 2007 14:28:15 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@harmony.apache.org From: tellison@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070902212815.6B6861A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 + } } /**