You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/06/20 16:06:57 UTC
svn commit: r415647 - in
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src:
main/java/java/io/SequenceInputStream.java
test/java/tests/api/java/io/SequenceInputStreamTest.java
Author: tellison
Date: Tue Jun 20 07:06:56 2006
New Revision: 415647
URL: http://svn.apache.org/viewvc?rev=415647&view=rev
Log:
SequenceInputStream throws wrong exception when two args invalid.
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java?rev=415647&r1=415646&r2=415647&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java Tue Jun 20 07:06:56 2006
@@ -18,6 +18,7 @@
import java.util.Enumeration;
import java.util.Vector;
+import org.apache.harmony.luni.util.Msg;
/**
* SequenceInputStream is used for streaming over a sequence of streams
@@ -100,19 +101,20 @@
* If an error occurs attempting to close this FileInputStream.
*/
public void close() throws IOException {
- if (e != null) {
- while (in != null) {
- nextStream();
- }
- e = null;
- } else {
- throw new IOException(org.apache.harmony.luni.util.Msg.getString("K00b7")); //$NON-NLS-1$
- }
+ if (e == null) {
+ throw new IOException(Msg.getString("K00b7")); //$NON-NLS-1$
+ }
+
+ while (in != null) {
+ nextStream();
+ }
+ e = null;
}
/**
* Sets up the next InputStream or leaves it alone if there are none left.
- * @throws IOException
+ *
+ * @throws IOException
*/
private void nextStream() throws IOException {
if (in != null) {
@@ -169,34 +171,25 @@
* occurs.
*/
public int read(byte[] buffer, int offset, int count) throws IOException {
+ if (in == null) {
+ return -1;
+ }
if (buffer == null) {
- // avoid int overflow
- if (offset >= 0 && count >= 0) {
- while (in != null) {
- long result = in.skip(count);
- if (result >= 0) {
- return (int) result;
- }
- nextStream();
+ throw new NullPointerException();
+ }
+ // avoid int overflow
+ if (0 <= offset && offset <= buffer.length && 0 <= count
+ && count <= buffer.length - offset) {
+ while (in != null) {
+ int result = in.read(buffer, offset, count);
+ if (result >= 0) {
+ return result;
}
- } else {
- throw new ArrayIndexOutOfBoundsException();
- }
+ nextStream();
+ }
+ return -1;
} else {
- // avoid int overflow
- if (0 <= offset && offset <= buffer.length && 0 <= count
- && count <= buffer.length - offset) {
- while (in != null) {
- int result = in.read(buffer, offset, count);
- if (result >= 0) {
- return result;
- }
- nextStream();
- }
- } else {
- throw new ArrayIndexOutOfBoundsException();
- }
+ throw new ArrayIndexOutOfBoundsException();
}
- return -1;
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java?rev=415647&r1=415646&r2=415647&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java Tue Jun 20 07:06:56 2006
@@ -119,7 +119,7 @@
/**
* @tests java.io.SequenceInputStream#read(byte[], int, int)
*/
- public void test_read$BII() {
+ public void test_read$BII() throws IOException {
// Test for method int java.io.SequenceInputStream.read(byte [], int,
// int)
try {
@@ -130,6 +130,19 @@
buf).equals(s1 + s2));
} catch (IOException e) {
fail("IOException during read test : " + e.getMessage());
+ }
+
+ ByteArrayInputStream bis1 = new ByteArrayInputStream(
+ new byte[] { 1, 2, 3, 4 });
+ ByteArrayInputStream bis2 = new ByteArrayInputStream(
+ new byte[] { 5, 6, 7, 8 });
+ SequenceInputStream sis = new SequenceInputStream(bis1, bis2);
+
+ try {
+ sis.read(null, 0, -1);
+ fail("Expected NullPointerException exception");
+ } catch (NullPointerException e) {
+ // expected
}
}