harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r431833 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectOutputStream.java test/java/tests/api/java/io/ObjectOutputStreamTest.java
Date Wed, 16 Aug 2006 05:48:39 GMT
Author: pyang
Date: Tue Aug 15 22:48:38 2006
New Revision: 431833

URL: http://svn.apache.org/viewvc?rev=431833&view=rev
Log:
Patch applied for HARMONY-1192 ([classlib][luni] java.io.ObjectOutputStream.writeObject()
behaves incorrect when trying to serialize a non serializable object)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java?rev=431833&r1=431832&r2=431833&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
Tue Aug 15 22:48:38 2006
@@ -1750,9 +1750,6 @@
 
 	private void writeObject(Object object, boolean unshared)
 			throws IOException {
-		if (object != null && !ObjectStreamClass.isSerializable(object.getClass())) {
-			throw new NotSerializableException(object.getClass().getName());
-		}
 		boolean setOutput = (primitiveTypes == output);
 		if (setOutput) {
 			primitiveTypes = null;
@@ -1811,6 +1808,9 @@
 	private Integer writeObjectInternal(Object object, boolean unshared,
 			boolean computeClassBasedReplacement,
 			boolean computeStreamReplacement) throws IOException {
+        if (object != null && !ObjectStreamClass.isSerializable(object.getClass()))
{
+            throw new NotSerializableException(object.getClass().getName());
+        }
 		if (object == null) {
 			writeNull();
 			return null;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java?rev=431833&r1=431832&r2=431833&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
Tue Aug 15 22:48:38 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
 import java.io.OutputStream;
 import java.io.Serializable;
 import java.io.SerializablePermission;
+import java.io.WriteAbortedException;
 import java.security.Permission;
 import java.util.Arrays;
 
@@ -927,6 +928,36 @@
         oos.close();
         ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
         assertEquals("Wrote incorrect UTF value", "HelloWorld", ois.readUTF());
+    }
+    
+    /**
+     * @tests java.io.ObjectOutputStream#writeObject(java.lang.Object)
+     */
+    public void test_writeObject_Exception() throws ClassNotFoundException, IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+        try {
+            oos.writeObject(new Object());
+            fail("should throw ObjectStreamException");
+        } catch (ObjectStreamException e) {
+            // expected
+        } finally {
+            oos.close();
+            baos.close();
+        }
+
+        byte[] bytes = baos.toByteArray();
+        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
+                bytes));
+        try {
+            ois.readObject();
+            fail("should throw WriteAbortedException");
+        } catch (WriteAbortedException e) {
+            // expected
+        } finally {
+            ois.close();
+        }
     }
 
     /**



Mime
View raw message