harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r429672 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/PipedOutputStream.java test/java/tests/api/java/io/PipedOutputStreamTest.java
Date Tue, 08 Aug 2006 14:53:32 GMT
Author: pyang
Date: Tue Aug  8 07:53:31 2006
New Revision: 429672

URL: http://svn.apache.org/viewvc?rev=429672&view=rev
Log:
Fix for HARMONY-1096([classlib][luni] java.io.PipedOutputStream.connect should throw NullPointerException)
AND HARMONY-1099 ([classlib][io] java.io.PipedOutputStream.write(byte[], int, int) throws
unexpected IndexOutOfBoundsException)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedOutputStream.java?rev=429672&r1=429671&r2=429672&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedOutputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedOutputStream.java
Tue Aug  8 07:53:31 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.
@@ -81,6 +81,9 @@
 	 *             If this Stream or the dest is already connected.
 	 */
 	public void connect(PipedInputStream stream) throws IOException {
+        if(null == stream){
+            throw new NullPointerException();
+        }
 		if (this.dest == null) {
 			if (!stream.isConnected) {
 				stream.buffer = new byte[PipedInputStream.PIPE_SIZE];
@@ -135,7 +138,10 @@
 	 *             If any of the arguments are out of bounds.
 	 */
 	public void write(byte buffer[], int offset, int count) throws IOException {
-		super.write(buffer, offset, count);
+		if (dest == null){
+            throw new IOException("Pipe not connected.");
+        }
+        super.write(buffer, offset, count);
 	}
 
 	/**
@@ -163,6 +169,6 @@
 		if (dest != null)
 			dest.receive(oneByte);
 		else
-			throw new IOException();
+			throw new IOException(org.apache.harmony.luni.util.Msg.getString("K007b"));
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java?rev=429672&r1=429671&r2=429672&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java
Tue Aug  8 07:53:31 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.
@@ -108,6 +108,20 @@
 			fail("Exception during close : " + e.getMessage());
 		}
 	}
+    
+    /**
+     * @tests java.io.PipedOutputStream#connect(java.io.PipedInputStream)
+     */
+    public void test_connectLjava_io_PipedInputStream_Exception() throws IOException {
+        out = new PipedOutputStream();
+        out.connect(new PipedInputStream());
+        try {
+            out.connect(null);
+            fail("should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
 
 	/**
 	 * @tests java.io.PipedOutputStream#connect(java.io.PipedInputStream)



Mime
View raw message