summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2013-11-20 17:54:57 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-11-20 17:54:57 +0000
commit2e8bdf3373bd03428d5e122868e760b7e1377a46 (patch)
tree7bbeee97eb8fb613556942734e6ad06a8cf98f4a
parent270ee7a8ac9a4289070cb4c48dcd440637b79f28 (diff)
parent0048bf7983e68d6d99b7b1332db8a2239de50949 (diff)
downloadlibcore-2e8bdf3373bd03428d5e122868e760b7e1377a46.zip
libcore-2e8bdf3373bd03428d5e122868e760b7e1377a46.tar.gz
libcore-2e8bdf3373bd03428d5e122868e760b7e1377a46.tar.bz2
Merge "Make PipedWriter#flush throw if the reader is closed."
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/PipedWriterTest.java15
-rw-r--r--luni/src/main/java/java/io/PipedReader.java2
-rw-r--r--luni/src/main/java/java/io/PipedWriter.java5
3 files changed, 10 insertions, 12 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/PipedWriterTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/PipedWriterTest.java
index 99827a1..07c77b9 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/PipedWriterTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/PipedWriterTest.java
@@ -32,8 +32,7 @@ public class PipedWriterTest extends junit.framework.TestCase {
try {
pr = new PipedReader(pw);
} catch (IOException e) {
- System.out.println("Exception setting up reader: "
- + e.toString());
+ fail();
}
}
@@ -51,9 +50,7 @@ public class PipedWriterTest extends junit.framework.TestCase {
buf[i] = (char) r;
}
} catch (Exception e) {
- System.out.println("Exception reading ("
- + Thread.currentThread().getName() + "): "
- + e.toString());
+ fail();
}
}
}
@@ -85,7 +82,7 @@ public class PipedWriterTest extends junit.framework.TestCase {
rdrThread.start();
pw.write(buf);
pw.close();
- rdrThread.join(500);
+ rdrThread.join();
assertEquals("Failed to construct writer", "HelloWorld", new String(
reader.buf));
}
@@ -123,7 +120,7 @@ public class PipedWriterTest extends junit.framework.TestCase {
rdrThread.start();
pw.write(buf);
pw.close();
- rdrThread.join(500);
+ rdrThread.join();
assertEquals("Failed to write correct chars", "HelloWorld", new String(
reader.buf));
}
@@ -140,7 +137,7 @@ public class PipedWriterTest extends junit.framework.TestCase {
rdrThread.start();
pw.write(buf);
pw.flush();
- rdrThread.join(700);
+ rdrThread.join();
assertEquals("Failed to flush chars", "HelloWorld", new String(
reader.buf));
}
@@ -185,7 +182,7 @@ public class PipedWriterTest extends junit.framework.TestCase {
rdrThread.start();
pw.write(buf, 0, 10);
pw.close();
- rdrThread.join(1000);
+ rdrThread.join();
assertEquals("Failed to write correct chars", "HelloWorld", new String(
reader.buf));
}
diff --git a/luni/src/main/java/java/io/PipedReader.java b/luni/src/main/java/java/io/PipedReader.java
index 908505d..7bf9ed4 100644
--- a/luni/src/main/java/java/io/PipedReader.java
+++ b/luni/src/main/java/java/io/PipedReader.java
@@ -33,7 +33,7 @@ public class PipedReader extends Reader {
private Thread lastWriter;
- private boolean isClosed;
+ boolean isClosed;
/**
* The circular buffer through which data is passed. Data is read from the
diff --git a/luni/src/main/java/java/io/PipedWriter.java b/luni/src/main/java/java/io/PipedWriter.java
index ad8974b..e85f69c 100644
--- a/luni/src/main/java/java/io/PipedWriter.java
+++ b/luni/src/main/java/java/io/PipedWriter.java
@@ -17,8 +17,6 @@
package java.io;
-import java.util.Arrays;
-
/**
* Places information on a communications pipe. When two threads want to pass
* data back and forth, one creates a piped writer and the other creates a piped
@@ -115,6 +113,9 @@ public class PipedWriter extends Writer {
}
synchronized (reader) {
+ if (reader.isClosed) {
+ throw new IOException("Pipe is broken");
+ }
reader.notifyAll();
}
}