Index: src/main/java/java/io/PipedWriter.java =================================================================== --- src/main/java/java/io/PipedWriter.java (revision 496614) +++ src/main/java/java/io/PipedWriter.java (working copy) @@ -144,14 +144,6 @@ */ @Override public void write(char buffer[], int offset, int count) throws IOException { - if (buffer == null) { - throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$ - } - // avoid int overflow - if (offset < 0 || offset > buffer.length || count < 0 - || count > buffer.length - offset) { - throw new IndexOutOfBoundsException(); - } synchronized (lock) { if (closed) { throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$ @@ -159,6 +151,16 @@ if (dest == null) { throw new IOException(Msg.getString("K007b")); //$NON-NLS-1$ } + + if (buffer == null) { + throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$ + } + + // avoid int overflow + if (offset < 0 || offset > buffer.length || count < 0 + || count > buffer.length - offset) { + throw new IndexOutOfBoundsException(); + } dest.receive(buffer, offset, count); } } Index: src/test/java/tests/api/java/io/PipedWriterTest.java =================================================================== --- src/test/java/tests/api/java/io/PipedWriterTest.java (revision 496614) +++ src/test/java/tests/api/java/io/PipedWriterTest.java (working copy) @@ -239,6 +239,55 @@ fail("NullPointerException expected"); } catch (NullPointerException t) {} } + + /** + * @tests java.io.PipedWriter#write(char[], int, int) + */ + public void test_write$CII_notConnected() throws IOException { + // Regression test for Harmony-2404 + // create not connected pipe + PipedWriter obj = new PipedWriter(); + + // char array is null + try { + obj.write((char[]) null, 0, 1); + fail("IOException expected"); + } catch (IOException ioe) { + // expected + } + + // negative offset + try { + obj.write( new char[] { 1 }, -10, 1); + fail("IOException expected"); + } catch (IOException ioe) { + // expected + } + + // wrong offset + try { + obj.write( new char[] { 1 }, 10, 1); + fail("IOException expected"); + } catch (IOException ioe) { + // expected + } + + // negative length + try { + obj.write( new char[] { 1 }, 0, -10); + fail("IOException expected"); + } catch (IOException ioe) { + // expected + } + + // all valid params + try { + obj.write( new char[] { 1, 1 }, 0, 1); + fail("IOException expected"); + } catch (IOException ioe) { + // expected + } + } /** * @tests java.io.PipedWriter#write(int)