8204930: Reader:nullReader() spec does not match the behavior

Reviewed-by: bpb, rriggs
This commit is contained in:
Patrick Reinhart 2018-06-25 14:36:16 -07:00 committed by Brian Burkhalter
parent 123fee1d38
commit f44956330d
2 changed files with 20 additions and 5 deletions

View file

@ -63,13 +63,12 @@ public abstract class Reader implements Readable, Closeable {
* *
* <p> While the stream is open, the {@code read()}, {@code read(char[])}, * <p> While the stream is open, the {@code read()}, {@code read(char[])},
* {@code read(char[], int, int)}, {@code read(Charbuffer)}, {@code * {@code read(char[], int, int)}, {@code read(Charbuffer)}, {@code
* ready())}, {@code skip(long)}, and {@code transferTo()} methods all * ready()}, {@code skip(long)}, and {@code transferTo()} methods all
* behave as if end of stream has been reached. After the stream has been * behave as if end of stream has been reached. After the stream has been
* closed, these methods all throw {@code IOException}. * closed, these methods all throw {@code IOException}.
* *
* <p> The {@code markSupported()} method returns {@code false}. The * <p> The {@code markSupported()} method returns {@code false}. The
* {@code mark()} method does nothing, and the {@code reset()} method * {@code mark()} and {@code reset()} methods throw an {@code IOException}.
* throws {@code IOException}.
* *
* <p> The {@link #lock object} used to synchronize operations on the * <p> The {@link #lock object} used to synchronize operations on the
* returned {@code Reader} is not specified. * returned {@code Reader} is not specified.
@ -114,6 +113,12 @@ public abstract class Reader implements Readable, Closeable {
return 0; return 0;
} }
@Override
public boolean ready() throws IOException {
ensureOpen();
return false;
}
@Override @Override
public long skip(long n) throws IOException { public long skip(long n) throws IOException {
ensureOpen(); ensureOpen();

View file

@ -35,7 +35,7 @@ import static org.testng.Assert.*;
/* /*
* @test * @test
* @bug 8196298 * @bug 8196298 8204930
* @run testng NullReader * @run testng NullReader
* @summary Check for expected behavior of Reader.nullReader(). * @summary Check for expected behavior of Reader.nullReader().
*/ */
@ -95,6 +95,11 @@ public class NullReader {
"read(CharBuffer) != 0"); "read(CharBuffer) != 0");
} }
@Test(groups = "open")
public static void testReady() throws IOException {
assertFalse(openReader.ready());
}
@Test(groups = "open") @Test(groups = "open")
public static void testSkip() throws IOException { public static void testSkip() throws IOException {
assertEquals(0, openReader.skip(1), "skip() != 0"); assertEquals(0, openReader.skip(1), "skip() != 0");
@ -128,6 +133,11 @@ public class NullReader {
closedReader.read(charBuffer); closedReader.read(charBuffer);
} }
@Test(groups = "closed", expectedExceptions = IOException.class)
public static void testReadyClosed() throws IOException {
closedReader.ready();
}
@Test(groups = "closed", expectedExceptions = IOException.class) @Test(groups = "closed", expectedExceptions = IOException.class)
public static void testSkipClosed() throws IOException { public static void testSkipClosed() throws IOException {
closedReader.skip(1); closedReader.skip(1);