8204930: Reader:nullReader() spec does not match the behavior
authorbpb
Mon, 25 Jun 2018 14:36:16 -0700
changeset 50770 c545db4fc9bd
parent 50769 1bf8f9840705
child 50771 9ca95539747d
8204930: Reader:nullReader() spec does not match the behavior Reviewed-by: bpb, rriggs Contributed-by: Patrick Reinhart <patrick@reini.net>
src/java.base/share/classes/java/io/Reader.java
test/jdk/java/io/Reader/NullReader.java
--- a/src/java.base/share/classes/java/io/Reader.java	Mon Jun 25 13:37:01 2018 +0200
+++ b/src/java.base/share/classes/java/io/Reader.java	Mon Jun 25 14:36:16 2018 -0700
@@ -63,13 +63,12 @@
      *
      * <p> While the stream is open, the {@code read()}, {@code read(char[])},
      * {@code read(char[], int, int)}, {@code read(Charbuffer)}, {@code
-     * ready())}, {@code skip(long)}, and {@code transferTo()} methods all
-     * behave as if end of stream has been reached.  After the stream has been
+     * ready()}, {@code skip(long)}, and {@code transferTo()} methods all
+     * behave as if end of stream has been reached. After the stream has been
      * closed, these methods all throw {@code IOException}.
      *
      * <p> The {@code markSupported()} method returns {@code false}.  The
-     * {@code mark()} method does nothing, and the {@code reset()} method
-     * throws {@code IOException}.
+     * {@code mark()} and {@code reset()} methods throw an {@code IOException}.
      *
      * <p> The {@link #lock object} used to synchronize operations on the
      * returned {@code Reader} is not specified.
@@ -115,6 +114,12 @@
             }
 
             @Override
+            public boolean ready() throws IOException {
+                ensureOpen();
+                return false;
+            }
+
+            @Override
             public long skip(long n) throws IOException {
                 ensureOpen();
                 return 0L;
--- a/test/jdk/java/io/Reader/NullReader.java	Mon Jun 25 13:37:01 2018 +0200
+++ b/test/jdk/java/io/Reader/NullReader.java	Mon Jun 25 14:36:16 2018 -0700
@@ -35,7 +35,7 @@
 
 /*
  * @test
- * @bug 8196298
+ * @bug 8196298 8204930
  * @run testng NullReader
  * @summary Check for expected behavior of Reader.nullReader().
  */
@@ -96,6 +96,11 @@
     }
 
     @Test(groups = "open")
+    public static void testReady() throws IOException {
+        assertFalse(openReader.ready());
+    }
+
+    @Test(groups = "open")
     public static void testSkip() throws IOException {
         assertEquals(0, openReader.skip(1), "skip() != 0");
     }
@@ -129,6 +134,11 @@
     }
 
     @Test(groups = "closed", expectedExceptions = IOException.class)
+    public static void testReadyClosed() throws IOException {
+        closedReader.ready();
+    }
+
+    @Test(groups = "closed", expectedExceptions = IOException.class)
     public static void testSkipClosed() throws IOException {
         closedReader.skip(1);
     }