Index: src/test/java/tests/api/java/io/BufferedOutputStreamTest.java =================================================================== --- src/test/java/tests/api/java/io/BufferedOutputStreamTest.java (revision 442780) +++ src/test/java/tests/api/java/io/BufferedOutputStreamTest.java (working copy) @@ -249,6 +249,300 @@ } } + /** + * @tests java.io.BufferedOutputStream#write(byte[], int, int) + */ + public void test_write_$BII_NullStream_NullArray() throws IOException { + OutputStream bos = new BufferedOutputStream(null); + byte[] nullByteArray = null; + + try { + bos.write(nullByteArray, -1, -1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 0, -1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 1, -1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, -1, 0); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 0, 0); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 1, 0); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, -1, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 0, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 1, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * @tests java.io.BufferedOutputStream#write(byte[], int, int) + */ + public void test_write_$BII_NullStream_NullArray_Size() throws IOException { + OutputStream bos = new BufferedOutputStream(null, 1); + byte[] nullByteArray = null; + + try { + bos.write(nullByteArray, -1, -1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 0, -1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 1, -1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, -1, 0); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 0, 0); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 1, 0); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, -1, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 0, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(nullByteArray, 1, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * @tests java.io.BufferedOutputStream#write(byte[], int, int) + */ + public void test_write_$BII_NullStream() throws IOException { + BufferedOutputStream bos = new BufferedOutputStream(null); + byte[] byteArray = new byte[10]; + + try { + bos.write(byteArray, -1, -1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + try { + bos.write(byteArray, 0, -1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + try { + bos.write(byteArray, 1, -1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + try { + bos.write(byteArray, -1, 0); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + bos.write(byteArray, 0, 0); + + bos.write(byteArray, 1, 0); + + bos.write(byteArray, byteArray.length, 0); + + try { + bos.write(byteArray, byteArray.length + 1, 0); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + //expected + } + + try { + bos.write(byteArray, -1, 1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + bos.write(byteArray, 0, 1); + bos.write(byteArray, 1, 1); + + bos.write(byteArray, 0, byteArray.length); + + try { + bos.write(byteArray, byteArray.length + 1, 1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + //expected + } + } + + /** + * @tests java.io.BufferedOutputStream#write(byte[], int, int) + */ + public void test_write_$BII_NullStream_Size() throws IOException { + BufferedOutputStream bos = new BufferedOutputStream(null, 1); + byte[] byteArray = new byte[10]; + + try { + bos.write(byteArray, -1, -1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + try { + bos.write(byteArray, 0, -1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + try { + bos.write(byteArray, 1, -1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + try { + bos.write(byteArray, -1, 0); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + bos.write(byteArray, 0, 0); + + bos.write(byteArray, 1, 0); + + bos.write(byteArray, byteArray.length, 0); + + try { + bos.write(byteArray, byteArray.length + 1, 0); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + //expected + } + + try { + bos.write(byteArray, -1, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(byteArray, 0, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(byteArray, 0, byteArray.length); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(byteArray, 1, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + bos.write(byteArray, byteArray.length + 1, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + //expected + } + } + /** * @tests java.io.BufferedOutputStream#write(int) */ Index: src/main/java/java/io/BufferedOutputStream.java =================================================================== --- src/main/java/java/io/BufferedOutputStream.java (revision 442780) +++ src/main/java/java/io/BufferedOutputStream.java (working copy) @@ -121,14 +121,14 @@ throw new NullPointerException(org.apache.harmony.luni.util.Msg .getString("K0047")); //$NON-NLS-1$ } + if (count == 0 && length >= buf.length) { + out.write(buffer, offset, length); + return; + } if (offset < 0 || offset > buffer.length - length || length < 0) { throw new ArrayIndexOutOfBoundsException( org.apache.harmony.luni.util.Msg.getString("K002f")); //$NON-NLS-1$ } - if (count == 0 && length >= buf.length) { - out.write(buffer, offset, length); - return; - } int available = buf.length - count; if (length < available) { available = length;