harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r421594 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni: build.xml src/main/java/java/io/ObjectInputStream.java src/main/java/java/io/ObjectOutputStream.java src/test/java/tests/api/java/io/ObjectInputStreamTest.java
Date Thu, 13 Jul 2006 11:24:23 GMT
Author: mloenko
Date: Thu Jul 13 04:24:22 2006
New Revision: 421594

URL: http://svn.apache.org/viewvc?rev=421594&view=rev
Log:
enabling ObjectInputStreamTest, including integration of patch from HARMONY-844
[classlib][io] compatibility: java.io.ObjectInputStream.skipBytes(len<=0) returns len while
RI throws NPE

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/build.xml
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
    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/ObjectInputStreamTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/build.xml
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/build.xml?rev=421594&r1=421593&r2=421594&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/build.xml (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/build.xml Thu Jul 13 04:24:22 2006
@@ -395,7 +395,6 @@
                     <exclude name="tests/api/java/lang/IllegalThreadStateExceptionTest.java"
/>
                     <exclude name="tests/api/java/lang/ThreadTest.java" />
                     <exclude name="tests/api/java/io/InputStreamReaderTest.java" />
-                    <exclude name="tests/api/java/io/ObjectInputStreamTest.java" />
                     <exclude name="tests/api/java/io/ObjectOutputStreamTest.java" />
                     <exclude name="tests/api/java/io/OutputStreamWriterTest.java" />
                     <exclude name="tests/api/java/io/PipedInputStreamTest.java" />

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java?rev=421594&r1=421593&r2=421594&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
Thu Jul 13 04:24:22 2006
@@ -2542,7 +2542,11 @@
      */
     public int skipBytes(int length) throws IOException {
         // To be used with available. Ok to call if reading primitive buffer
-        int offset = 0;
+        if (input == null) {
+            throw new NullPointerException();
+        }
+
+    	int offset = 0;
         while (offset < length) {
             checkReadPrimitiveTypes();
             long skipped = primitiveData.skip(length - offset);

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=421594&r1=421593&r2=421594&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
Thu Jul 13 04:24:22 2006
@@ -196,7 +196,7 @@
 	 */
 	public ObjectOutputStream(OutputStream output) throws IOException {
 		Class<?> implementationClass = getClass();
-		Class<?> thisClass = ObjectInputStream.class;
+		Class<?> thisClass = ObjectOutputStream.class;
 		if (implementationClass != thisClass) {
 			boolean mustCheck = false;
 			try {
@@ -670,7 +670,7 @@
 	 *         The handle that this object was assigned when it was saved.
 	 */
 	private Integer registeredObjectHandleFor(Object obj) {
-		return (Integer) objectsWritten.get(obj);
+		return objectsWritten.get(obj);
 	}
 
 	/**
@@ -956,7 +956,7 @@
 		}
 		if (handle == null) {
             Class<?> classToWrite = classDesc.forClass();
-			Integer previousHandle = (Integer) objectsWritten.get(classDesc);
+			Integer previousHandle = objectsWritten.get(classDesc);
 			// If we got here, it is a new (non-null) classDesc that will have
 			// to be registered as well
 			handle = registerObjectWritten(classDesc);
@@ -1402,7 +1402,7 @@
 		output.writeByte(TC_ARRAY);
 		writeClassDescForClass(arrayClass);
 
-		Integer previousHandle = (Integer) objectsWritten.get(array);
+		Integer previousHandle = objectsWritten.get(array);
 		Integer handle = registerObjectWritten(array);
 		if (unshared) {
 			// remove reference to unshared object
@@ -1498,7 +1498,7 @@
 		// it.
 		writeClassDesc(ObjectStreamClass.lookupStreamClass(object), unshared);
 		
-		Integer previousHandle = (Integer) objectsWritten.get(object);
+		Integer previousHandle = objectsWritten.get(object);
 		Integer handle = registerObjectWritten(object);
 		if (unshared) {
 			// remove reference to unshared object
@@ -1626,7 +1626,7 @@
 		// Either serializable or externalizable, now we can save info
 		output.writeByte(TC_OBJECT);
 		writeClassDescForClass(theClass);
-		Integer previousHandle = (Integer) objectsWritten.get(object);
+		Integer previousHandle = objectsWritten.get(object);
 		Integer handle = registerObjectWritten(object);
 
 		// This is how we know what to do in defaultWriteObject. And it is also
@@ -1696,7 +1696,7 @@
 		}
 		output.writeUTFBytes(object, count);
 		
-		Integer previousHandle = (Integer) objectsWritten.get(object);
+		Integer previousHandle = objectsWritten.get(object);
 		Integer handle = registerObjectWritten(object);
 		if (unshared) {
 			// remove reference to unshared object
@@ -1944,7 +1944,7 @@
         classDesc.setSerialVersionUID(0L);
         // set flag for enum, the flag is (SC_SERIALIZABLE | SC_ENUM)
         classDesc.setFlags((byte)(SC_SERIALIZABLE|SC_ENUM));
-        Integer previousHandle = (Integer) objectsWritten.get(classDesc);
+        Integer previousHandle = objectsWritten.get(classDesc);
         Integer handle = null;
         if (!unshared) {
             handle = dumpCycle(classDesc);
@@ -1989,7 +1989,7 @@
         output.writeByte(TC_ENUM);
         ObjectStreamClass classDesc = writeEnumDesc(theClass, unshared);
 
-        Integer previousHandle = (Integer) objectsWritten.get(object);
+        Integer previousHandle = objectsWritten.get(object);
         Integer handle = registerObjectWritten(object);        
 
         ObjectStreamField[] fields = classDesc.getSuperclass().fields();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java?rev=421594&r1=421593&r2=421594&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
Thu Jul 13 04:24:22 2006
@@ -24,513 +24,412 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
+import java.io.SerializablePermission;
 import java.io.StreamCorruptedException;
+import java.security.Permission;
 import java.util.Hashtable;
 import java.util.Vector;
 
 import tests.support.resource.Support_Resources;
 
 public class ObjectInputStreamTest extends junit.framework.TestCase implements
-		Serializable {
+        Serializable {
 
-	ObjectInputStream ois;
+    ObjectInputStream ois;
 
-	ObjectOutputStream oos;
+    ObjectOutputStream oos;
 
-	ByteArrayOutputStream bao;
+    ByteArrayOutputStream bao;
 
-	public class SerializableTestHelper implements Serializable {
-		public String aField1;
-
-		public String aField2;
-
-		SerializableTestHelper() {
-			aField1 = null;
-			aField2 = null;
-		}
-
-		SerializableTestHelper(String s, String t) {
-			aField1 = s;
-			aField2 = t;
-		}
-
-		private void readObject(ObjectInputStream ois) throws IOException {
-			// note aField2 is not read
-			try {
-				ObjectInputStream.GetField fields = ois.readFields();
-				aField1 = (String) fields.get("aField1", "Zap");
-			} catch (Exception e) {
-				System.out.println("Exception during test: " + e.toString());
-			}
-		}
-
-		private void writeObject(ObjectOutputStream oos) throws IOException {
-			// note aField2 is not written
-			ObjectOutputStream.PutField fields = oos.putFields();
-			fields.put("aField1", aField1);
-			oos.writeFields();
-		}
-
-		public String getText1() {
-			return aField1;
-		}
-
-		public void setText1(String s) {
-			aField1 = s;
-		}
-
-		public String getText2() {
-			return aField2;
-		}
-
-		public void setText2(String s) {
-			aField2 = s;
-		}
-	}
-
-	public static class A1 implements Serializable {
-		static final long serialVersionUID = 5942584913446079661L;
-
-		B1 b1 = new B1();
-
-		B1 b2 = b1;
-
-		Vector v = new Vector();
-	}
-
-	public static class B1 implements Serializable {
-		int i = 5;
-
-		Hashtable h = new Hashtable();
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readObject()
-	 */
-	public void test_readObjectMissingClasses() {
-		try {
-			// To create or update the resource, uncomment the following, and
-			// the B1 class definition and references above.
-			ObjectOutputStream out = new ObjectOutputStream(
-					new FileOutputStream("hyts_missingclass.ser"));
-			out.writeObject(new tests.api.java.io.ObjectInputStreamTest.A1());
-			out.close();
-
-			ObjectInputStream in = new ObjectInputStream(Support_Resources
-					.getStream("hyts_missingclass.ser"));
-			in.readObject();
-			in.close();
-			// the serialized data should load without any exceptions.
-		} catch (Exception e) {
-			e.printStackTrace();
-			fail("unexpected: " + e);
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
-	 */
-	public void test_ConstructorLjava_io_InputStream() {
-		// Test for method java.io.ObjectInputStream(java.io.InputStream)
-		try {
-			oos.writeDouble(Double.MAX_VALUE);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			ois.close();
-			oos.close();
-		} catch (IOException e) {
-			fail("Exception contructing stream : " + e.getMessage());
-		}
-		boolean exception = false;
-		try {
-			ois = new ObjectInputStream(new ByteArrayInputStream(new byte[90]));
-		} catch (StreamCorruptedException e) {
-			// Correct
-			exception = true;
-		} catch (IOException e) {
-			fail("Exception contructing stream : " + e.getMessage());
-		}
-		assertTrue("Expected exception", exception);
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
-	 */
-	public void test_ConstructorLjava_io_InputStream_subtest0() {
-		System.setSecurityManager(new SecurityManager());
-		try {
-			ByteArrayOutputStream out = new ByteArrayOutputStream();
-			ObjectOutputStream obout = new ObjectOutputStream(out);
-			obout.write(0);
-			obout.close();
-			InputStream in = new ByteArrayInputStream(out.toByteArray());
-			// should not cause SecurityException
-			new ObjectInputStream(in);
-			class SubTest1 extends ObjectInputStream {
-				SubTest1(InputStream in) throws IOException {
-					super(in);
-				}
-			}
-			;
-			in.reset();
-			// should not cause SecurityException
-			new SubTest1(in);
-			class SubTest2 extends ObjectInputStream {
-				SubTest2(InputStream in) throws IOException {
-					super(in);
-				}
-
-				public Object readUnshared() throws IOException,
-						ClassNotFoundException {
-					return null;
-				}
-			}
-			;
-			in.reset();
-			try {
-				new SubTest2(in);
-				fail("should throw SecurityException 1");
-			} catch (SecurityException e) {
-			}
-			class SubTest3 extends ObjectInputStream {
-				SubTest3(InputStream in) throws IOException {
-					super(in);
-				}
-
-				public GetField readFields() throws IOException,
-						ClassNotFoundException, NotActiveException {
-					return null;
-				}
-			}
-			;
-			in.reset();
-			try {
-				new SubTest3(in);
-				fail("should throw SecurityException 2");
-			} catch (SecurityException e) {
-			}
-		} catch (IOException e) {
-			fail("Unexpeced: " + e);
-		} finally {
-			System.setSecurityManager(null);
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#available()
-	 */
-	public void test_available() {
-		// Test for method int java.io.ObjectInputStream.available()
-		try {
-			oos.writeBytes("HelloWorld");
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertEquals("Read incorrect bytes", 10, ois.available());
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#close()
-	 */
-	public void test_close() {
-		// Test for method void java.io.ObjectInputStream.close()
-		try {
-			oos.writeBytes("HelloWorld");
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			ois.close();
-		} catch (IOException e) {
-			fail("Failed closing stream : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#defaultReadObject()
-	 */
-	public void test_defaultReadObject() {
-		// Test for method void java.io.ObjectInputStream.defaultReadObject()
-		// SM. This method may as well be private, as if called directly it
-		// throws an exception.
-		try {
-			String s = "HelloWorld";
-			oos.writeObject(s);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			ois.defaultReadObject();
-			fail("defaultReadObject should fail.");
-			ois.close();
-		} catch (NotActiveException e) {
-			// Desired behavior.
-			return;
-		} catch (Exception e) {
-			fail("Wrong exception during test : " + e.getMessage());
-		}
-		fail("defaultReadObject should have thrown exception");
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#read()
-	 */
-	public void test_read() {
-		// Test for method int java.io.ObjectInputStream.read()
-		try {
-			oos.write('T');
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertEquals("Read incorrect byte value", 'T', ois.read());
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#read(byte[], int, int)
-	 */
-	public void test_read$BII() {
-		// Test for method int java.io.ObjectInputStream.read(byte [], int, int)
-		try {
-			byte[] buf = new byte[10];
-			oos.writeBytes("HelloWorld");
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			ois.read(buf, 0, 10);
-			ois.close();
-			assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0, 10)
-					);
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readBoolean()
-	 */
-	public void test_readBoolean() {
-		// Test for method boolean java.io.ObjectInputStream.readBoolean()
-		try {
-			oos.writeBoolean(true);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertTrue("Read incorrect boolean value", ois.readBoolean());
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readByte()
-	 */
-	public void test_readByte() {
-		// Test for method byte java.io.ObjectInputStream.readByte()
-		try {
-			oos.writeByte(127);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertEquals("Read incorrect byte value", 127, ois.readByte());
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readChar()
-	 */
-	public void test_readChar() {
-		// Test for method char java.io.ObjectInputStream.readChar()
-		try {
-			oos.writeChar('T');
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertEquals("Read incorrect char value", 'T', ois.readChar());
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readDouble()
-	 */
-	public void test_readDouble() {
-		// Test for method double java.io.ObjectInputStream.readDouble()
-		try {
-			oos.writeDouble(Double.MAX_VALUE);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertTrue("Read incorrect double value",
-					ois.readDouble() == Double.MAX_VALUE);
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readFields()
-	 */
-	public void test_readFields() {
-		// Test for method java.io.ObjectInputStream$GetField
-		// java.io.ObjectInputStream.readFields()
-
-		SerializableTestHelper sth;
-
-		/*
-		 * "SerializableTestHelper" is an object created for these tests with
-		 * two fields (Strings) and simple implementations of readObject and
-		 * writeObject which simply read and write the first field but not the
-		 * second
-		 */
-
-		try {
-			oos.writeObject(new SerializableTestHelper("Gabba", "Jabba"));
-			oos.flush();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			sth = (SerializableTestHelper) (ois.readObject());
-			assertEquals("readFields / writeFields failed--first field not set",
-					"Gabba", sth.getText1());
-			assertNull(
-					"readFields / writeFields failed--second field should not have been set",
-					sth.getText2());
-		} catch (Exception e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readFloat()
-	 */
-	public void test_readFloat() {
-		// Test for method float java.io.ObjectInputStream.readFloat()
-		try {
-			oos.writeFloat(Float.MAX_VALUE);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertTrue("Read incorrect float value",
-					ois.readFloat() == Float.MAX_VALUE);
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readFully(byte[])
-	 */
-	public void test_readFully$B() {
-		// Test for method void java.io.ObjectInputStream.readFully(byte [])
-		try {
-			byte[] buf = new byte[10];
-			oos.writeBytes("HelloWorld");
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			ois.readFully(buf);
-			ois.close();
-			assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0, 10)
-					);
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readFully(byte[], int, int)
-	 */
-	public void test_readFully$BII() {
-		// Test for method void java.io.ObjectInputStream.readFully(byte [],
-		// int, int)
-		try {
-			byte[] buf = new byte[10];
-			oos.writeBytes("HelloWorld");
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			ois.readFully(buf, 0, 10);
-			ois.close();
-			assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0, 10)
-					);
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readInt()
-	 */
-	public void test_readInt() {
-		// Test for method int java.io.ObjectInputStream.readInt()
-		try {
-			oos.writeInt(Integer.MAX_VALUE);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertTrue("Read incorrect int value",
-					ois.readInt() == Integer.MAX_VALUE);
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readLine()
-	 */
-	public void test_readLine() {
-		// Test for method java.lang.String java.io.ObjectInputStream.readLine()
-		try {
-			oos.writeBytes("HelloWorld\nSecondLine");
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			ois.readLine();
-			assertEquals("Read incorrect string value", 
-					"SecondLine", ois.readLine());
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readLong()
-	 */
-	public void test_readLong() {
-		// Test for method long java.io.ObjectInputStream.readLong()
-		try {
-			oos.writeLong(Long.MAX_VALUE);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertTrue("Read incorrect long value",
-					ois.readLong() == Long.MAX_VALUE);
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readObject()
-	 */
-	public void test_readObject() throws Exception {
+    public class SerializableTestHelper implements Serializable {
+
+        public String aField1;
+
+        public String aField2;
+
+        SerializableTestHelper() {
+            aField1 = null;
+            aField2 = null;
+        }
+
+        SerializableTestHelper(String s, String t) {
+            aField1 = s;
+            aField2 = t;
+        }
+
+        private void readObject(ObjectInputStream ois) throws Exception {
+            // note aField2 is not read
+            ObjectInputStream.GetField fields = ois.readFields();
+            aField1 = (String) fields.get("aField1", "Zap");
+        }
+
+        private void writeObject(ObjectOutputStream oos) throws IOException {
+            // note aField2 is not written
+            ObjectOutputStream.PutField fields = oos.putFields();
+            fields.put("aField1", aField1);
+            oos.writeFields();
+        }
+
+        public String getText1() {
+            return aField1;
+        }
+
+        public void setText1(String s) {
+            aField1 = s;
+        }
+
+        public String getText2() {
+            return aField2;
+        }
+
+        public void setText2(String s) {
+            aField2 = s;
+        }
+    }
+
+    public static class A1 implements Serializable {
+
+        static final long serialVersionUID = 5942584913446079661L;
+
+        B1 b1 = new B1();
+
+        B1 b2 = b1;
+
+        Vector v = new Vector();
+    }
+
+    public static class B1 implements Serializable {
+
+        int i = 5;
+
+        Hashtable h = new Hashtable();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readObject()
+     */
+    public void test_readObjectMissingClasses() throws Exception {
+        // To create or update the resource, uncomment the following, and
+        // the B1 class definition and references above.
+        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
+                "hyts_missingclass.ser"));
+        out.writeObject(new tests.api.java.io.ObjectInputStreamTest.A1());
+        out.close();
+
+        ObjectInputStream in = new ObjectInputStream(Support_Resources
+                .getStream("hyts_missingclass.ser"));
+        in.readObject();
+        in.close();
+        // the serialized data should load without any exceptions.
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
+     */
+    public void test_ConstructorLjava_io_InputStream() throws IOException {
+        // Test for method java.io.ObjectInputStream(java.io.InputStream)
+        oos.writeDouble(Double.MAX_VALUE);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        ois.close();
+        oos.close();
+
+        try {
+            ois = new ObjectInputStream(new ByteArrayInputStream(new byte[90]));
+            fail("StreamCorruptedException expected");
+        } catch (StreamCorruptedException e) {}
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
+     */
+    public void test_ConstructorLjava_io_InputStream_subtest0() throws IOException {
+        SecurityManager sm = System.getSecurityManager();
+        System.setSecurityManager(new SecurityManager() {
+            Permission golden = new SerializablePermission("enableSubclassImplementation");
+            
+            public void checkPermission(Permission p) {
+                if (golden.equals(p)) {
+                    throw new SecurityException();
+                }
+            }
+        });
+
+        try {
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            ObjectOutputStream obout = new ObjectOutputStream(out);
+            obout.write(0);
+            obout.close();
+
+            InputStream in = new ByteArrayInputStream(out.toByteArray());
+
+            // should not cause SecurityException
+            new ObjectInputStream(in);
+            in.reset();
+
+            // should not cause SecurityException
+            new ObjectInputStream(in) {};
+            in.reset();
+
+            try {
+                new ObjectInputStream(in) {
+                    public Object readUnshared() throws IOException, ClassNotFoundException
{
+                        return null;
+                    }
+                };
+                fail("should throw SecurityException 1");
+            } catch (SecurityException e) {}
+
+            in.reset();
+            try {
+                new ObjectInputStream(in) {
+                    public GetField readFields() throws IOException,
+                            ClassNotFoundException, NotActiveException {
+                        return null;
+                    }
+                };
+                fail("should throw SecurityException 2");
+            } catch (SecurityException e) {}
+        } finally {
+            System.setSecurityManager(sm);
+        }
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#available()
+     */
+    public void test_available() throws IOException {
+        // Test for method int java.io.ObjectInputStream.available()
+        oos.writeBytes("HelloWorld");
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertEquals("Read incorrect bytes", 10, ois.available());
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#close()
+     */
+    public void test_close() throws IOException {
+        // Test for method void java.io.ObjectInputStream.close()
+        oos.writeBytes("HelloWorld");
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#defaultReadObject()
+     */
+    public void test_defaultReadObject() throws Exception {
+        // Test for method void java.io.ObjectInputStream.defaultReadObject()
+        // SM. This method may as well be private, as if called directly it
+        // throws an exception.
+        String s = "HelloWorld";
+        oos.writeObject(s);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        try {
+            ois.defaultReadObject();
+            fail("NotActiveException expected");
+        } catch (NotActiveException e) {
+            // Desired behavior
+        } finally {
+            ois.close();
+        }
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#read()
+     */
+    public void test_read() throws IOException {
+        // Test for method int java.io.ObjectInputStream.read()
+        oos.write('T');
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertEquals("Read incorrect byte value", 'T', ois.read());
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#read(byte[], int, int)
+     */
+    public void test_read$BII() throws IOException {
+        // Test for method int java.io.ObjectInputStream.read(byte [], int, int)
+        byte[] buf = new byte[10];
+        oos.writeBytes("HelloWorld");
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        ois.read(buf, 0, 10);
+        ois.close();
+        assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0,
+                10));
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readBoolean()
+     */
+    public void test_readBoolean() throws IOException {
+        // Test for method boolean java.io.ObjectInputStream.readBoolean()
+        oos.writeBoolean(true);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertTrue("Read incorrect boolean value", ois.readBoolean());
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readByte()
+     */
+    public void test_readByte() throws IOException {
+        // Test for method byte java.io.ObjectInputStream.readByte()
+        oos.writeByte(127);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertEquals("Read incorrect byte value", 127, ois.readByte());
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readChar()
+     */
+    public void test_readChar() throws IOException {
+        // Test for method char java.io.ObjectInputStream.readChar()
+        oos.writeChar('T');
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertEquals("Read incorrect char value", 'T', ois.readChar());
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readDouble()
+     */
+    public void test_readDouble() throws IOException {
+        // Test for method double java.io.ObjectInputStream.readDouble()
+        oos.writeDouble(Double.MAX_VALUE);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertTrue("Read incorrect double value",
+                ois.readDouble() == Double.MAX_VALUE);
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readFields()
+     */
+    public void test_readFields() throws Exception {
+        // Test for method java.io.ObjectInputStream$GetField
+        // java.io.ObjectInputStream.readFields()
+
+        SerializableTestHelper sth;
+
+        /*
+         * "SerializableTestHelper" is an object created for these tests with
+         * two fields (Strings) and simple implementations of readObject and
+         * writeObject which simply read and write the first field but not the
+         * second
+         */
+
+        oos.writeObject(new SerializableTestHelper("Gabba", "Jabba"));
+        oos.flush();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        sth = (SerializableTestHelper) (ois.readObject());
+        assertEquals("readFields / writeFields failed--first field not set",
+                "Gabba", sth.getText1());
+        assertNull(
+                "readFields / writeFields failed--second field should not have been set",
+                sth.getText2());
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readFloat()
+     */
+    public void test_readFloat() throws IOException {
+        // Test for method float java.io.ObjectInputStream.readFloat()
+        oos.writeFloat(Float.MAX_VALUE);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertTrue("Read incorrect float value",
+                ois.readFloat() == Float.MAX_VALUE);
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readFully(byte[])
+     */
+    public void test_readFully$B() throws IOException {
+        // Test for method void java.io.ObjectInputStream.readFully(byte [])
+        byte[] buf = new byte[10];
+        oos.writeBytes("HelloWorld");
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        ois.readFully(buf);
+        ois.close();
+        assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0,
+                10));
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readFully(byte[], int, int)
+     */
+    public void test_readFully$BII() throws IOException {
+        // Test for method void java.io.ObjectInputStream.readFully(byte [],
+        // int, int)
+        byte[] buf = new byte[10];
+        oos.writeBytes("HelloWorld");
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        ois.readFully(buf, 0, 10);
+        ois.close();
+        assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0,
+                10));
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readInt()
+     */
+    public void test_readInt() throws IOException {
+        // Test for method int java.io.ObjectInputStream.readInt()
+        oos.writeInt(Integer.MAX_VALUE);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertTrue("Read incorrect int value",
+                ois.readInt() == Integer.MAX_VALUE);
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readLine()
+     */
+    public void test_readLine() throws IOException {
+        // Test for method java.lang.String java.io.ObjectInputStream.readLine()
+        oos.writeBytes("HelloWorld\nSecondLine");
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        ois.readLine();
+        assertEquals("Read incorrect string value", "SecondLine", ois
+                .readLine());
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readLong()
+     */
+    public void test_readLong() throws IOException {
+        // Test for method long java.io.ObjectInputStream.readLong()
+        oos.writeLong(Long.MAX_VALUE);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertTrue("Read incorrect long value",
+                ois.readLong() == Long.MAX_VALUE);
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readObject()
+     */
+    public void test_readObject() throws Exception {
         // Test for method java.lang.Object
         // java.io.ObjectInputStream.readObject()
         String s = "HelloWorld";
@@ -612,152 +511,122 @@
                 out.toByteArray()));
         Object o = ois.readObject();
         assertEquals(C.class, o.getClass());
-	}
+    }
 
     public static class A implements Serializable {
+
         private static final long serialVersionUID = 11L;
 
         public String name = "name";
     }
 
-    public static class B extends A {
-    }
+    public static class B extends A {}
 
     public static class C extends B {
+
         private static final long serialVersionUID = 33L;
     }
 
-	/**
-	 * @tests java.io.ObjectInputStream#readObject()
-	 */
-	public void test_readObjectCorrupt() {
-		byte[] bytes = { 00, 00, 00, 0x64, 0x43, 0x48, (byte) 0xFD, 0x71, 00,
-				00, 0x0B, (byte) 0xB8, 0x4D, 0x65 };
-		ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
-		boolean exception = false;
-		try {
-			ObjectInputStream in = new ObjectInputStream(bin);
-			in.readObject();
-			fail("Unexpected read of corrupted stream");
-		} catch (StreamCorruptedException e) {
-			exception = true;
-		} catch (IOException e) {
-			fail("Unexpected: " + e);
-		} catch (ClassNotFoundException e) {
-			fail("Unexpected: " + e);
-		}
-		assertTrue("Expected StreamCorruptedException", exception);
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readShort()
-	 */
-	public void test_readShort() {
-		// Test for method short java.io.ObjectInputStream.readShort()
-		try {
-			oos.writeShort(Short.MAX_VALUE);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertTrue("Read incorrect short value",
-					ois.readShort() == Short.MAX_VALUE);
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readUnsignedByte()
-	 */
-	public void test_readUnsignedByte() {
-		// Test for method int java.io.ObjectInputStream.readUnsignedByte()
-		try {
-			oos.writeByte(-1);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertEquals("Read incorrect unsignedByte value", 255, ois
-					.readUnsignedByte());
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readUnsignedShort()
-	 */
-	public void test_readUnsignedShort() {
-		// Test for method int java.io.ObjectInputStream.readUnsignedShort()
-		try {
-			oos.writeShort(-1);
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertEquals("Read incorrect unsignedShort value", 65535, ois
-					.readUnsignedShort());
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#readUTF()
-	 */
-	public void test_readUTF() {
-		// Test for method java.lang.String java.io.ObjectInputStream.readUTF()
-		try {
-			oos.writeUTF("HelloWorld");
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			assertEquals("Read incorrect utf value", 
-					"HelloWorld", ois.readUTF());
-			ois.close();
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.ObjectInputStream#skipBytes(int)
-	 */
-	public void test_skipBytesI() {
-		// Test for method int java.io.ObjectInputStream.skipBytes(int)
-		try {
-			byte[] buf = new byte[10];
-			oos.writeBytes("HelloWorld");
-			oos.close();
-			ois = new ObjectInputStream(new ByteArrayInputStream(bao
-					.toByteArray()));
-			ois.skipBytes(5);
-			ois.read(buf, 0, 5);
-			ois.close();
-			assertEquals("Skipped incorrect bytes", "World", new String(buf, 0, 5)
-					);
-		} catch (IOException e) {
-			fail("Exception serializing data : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-		try {
-			oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
-		} catch (Exception e) {
-			fail("Setup failed : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-	}
+    /**
+     * @tests java.io.ObjectInputStream#readObject()
+     */
+    public void test_readObjectCorrupt() {
+        byte[] bytes = { 00, 00, 00, 0x64, 0x43, 0x48, (byte) 0xFD, 0x71, 00,
+                00, 0x0B, (byte) 0xB8, 0x4D, 0x65 };
+        ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
+        boolean exception = false;
+        try {
+            ObjectInputStream in = new ObjectInputStream(bin);
+            in.readObject();
+            fail("Unexpected read of corrupted stream");
+        } catch (StreamCorruptedException e) {
+            exception = true;
+        } catch (IOException e) {
+            fail("Unexpected: " + e);
+        } catch (ClassNotFoundException e) {
+            fail("Unexpected: " + e);
+        }
+        assertTrue("Expected StreamCorruptedException", exception);
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readShort()
+     */
+    public void test_readShort() throws IOException {
+        // Test for method short java.io.ObjectInputStream.readShort()
+        oos.writeShort(Short.MAX_VALUE);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertTrue("Read incorrect short value",
+                ois.readShort() == Short.MAX_VALUE);
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readUnsignedByte()
+     */
+    public void test_readUnsignedByte() throws IOException {
+        // Test for method int java.io.ObjectInputStream.readUnsignedByte()
+        oos.writeByte(-1);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertEquals("Read incorrect unsignedByte value", 255, ois
+                .readUnsignedByte());
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readUnsignedShort()
+     */
+    public void test_readUnsignedShort() throws IOException {
+        // Test for method int java.io.ObjectInputStream.readUnsignedShort()
+        oos.writeShort(-1);
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertEquals("Read incorrect unsignedShort value", 65535, ois
+                .readUnsignedShort());
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#readUTF()
+     */
+    public void test_readUTF() throws IOException {
+        // Test for method java.lang.String java.io.ObjectInputStream.readUTF()
+        oos.writeUTF("HelloWorld");
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        assertEquals("Read incorrect utf value", "HelloWorld", ois.readUTF());
+        ois.close();
+    }
+
+    /**
+     * @tests java.io.ObjectInputStream#skipBytes(int)
+     */
+    public void test_skipBytesI() throws IOException {
+        // Test for method int java.io.ObjectInputStream.skipBytes(int)
+        byte[] buf = new byte[10];
+        oos.writeBytes("HelloWorld");
+        oos.close();
+        ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+        ois.skipBytes(5);
+        ois.read(buf, 0, 5);
+        ois.close();
+        assertEquals("Skipped incorrect bytes", "World", new String(buf, 0, 5));
+
+        // Regression for HARMONY-844
+        try {
+            new ObjectInputStream() {}.skipBytes(0);
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {}
+    }
+
+    /**
+     * Sets up the fixture, for example, open a network connection. This method
+     * is called before a test is executed.
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
+    }
 }



Mime
View raw message