Index: modules/luni/src/main/java/java/io/PipedReader.java =================================================================== --- modules/luni/src/main/java/java/io/PipedReader.java (revision 792181) +++ modules/luni/src/main/java/java/io/PipedReader.java (working copy) @@ -139,6 +139,7 @@ /* Release buffer to indicate closed. */ data = null; } + isClosed = true; } } @@ -477,8 +478,11 @@ } } - void flush() { + void flush() throws IOException { synchronized (lock) { + if (isClosed) { + throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$ + } lock.notifyAll(); } } Index: modules/luni/src/main/java/java/io/PipedWriter.java =================================================================== --- modules/luni/src/main/java/java/io/PipedWriter.java (revision 792181) +++ modules/luni/src/main/java/java/io/PipedWriter.java (working copy) @@ -112,6 +112,13 @@ */ @Override public void flush() throws IOException { + synchronized(lock) + { + if (closed) { + throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$ + } + } + if (dest != null) { dest.flush(); } Index: modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedWriterTest.java =================================================================== --- modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedWriterTest.java (revision 792181) +++ modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedWriterTest.java (working copy) @@ -144,6 +144,34 @@ assertEquals("Failed to flush chars", "HelloWorld", new String( reader.buf)); } + + /** + * @tests java.io.PipedWriter#flush() + * Regression HARMONY-6293 + */ + public void test_flushAfterClose() throws Exception { + + pw = new PipedWriter(); + pw.close(); + try { + pw.flush(); + fail("should throw IOException"); + } catch (IOException e) { + // expected + System.out.println(e.getMessage()); + } + + PipedReader pr = new PipedReader(); + pw = new PipedWriter(pr); + pr.close(); + + try { + pw.flush(); + fail("should throw IOException"); + } catch (IOException e) { + // expected + } + } /** * @tests java.io.PipedWriter#write(char[], int, int)