diff options
| author | Brian Burkhalter <bpb@openjdk.org> | 2021-02-25 16:22:59 +0000 |
|---|---|---|
| committer | Brian Burkhalter <bpb@openjdk.org> | 2021-02-25 16:22:59 +0000 |
| commit | 5a9b70103cf9ef557591597d8a53cd9a4c05660f (patch) | |
| tree | eca43a70a110842be2887dad5ee4a60982a00ad3 /src/java.base/share/classes/java/io/StringReader.java | |
| parent | 7d4f60b16beda722c430f7d6c4b63a5d2a5eb79d (diff) | |
| download | openjdk-5a9b70103cf9ef557591597d8a53cd9a4c05660f.tar.gz openjdk-5a9b70103cf9ef557591597d8a53cd9a4c05660f.zip | |
8258444: Clean up specifications of java.io.Reader.read(char[],int,int) in subclass overrides
Reviewed-by: alanb, rriggs
Diffstat (limited to 'src/java.base/share/classes/java/io/StringReader.java')
| -rw-r--r-- | src/java.base/share/classes/java/io/StringReader.java | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/java.base/share/classes/java/io/StringReader.java b/src/java.base/share/classes/java/io/StringReader.java index 05f2cb5db42..caef7471e30 100644 --- a/src/java.base/share/classes/java/io/StringReader.java +++ b/src/java.base/share/classes/java/io/StringReader.java @@ -25,6 +25,7 @@ package java.io; +import java.util.Objects; /** * A character stream whose source is a string. @@ -76,23 +77,26 @@ public class StringReader extends Reader { /** * Reads characters into a portion of an array. * - * @param cbuf Destination buffer - * @param off Offset at which to start writing characters - * @param len Maximum number of characters to read + * <p> If {@code len} is zero, then no characters are read and {@code 0} is + * returned; otherwise, there is an attempt to read at least one character. + * If no character is available because the stream is at its end, the value + * {@code -1} is returned; otherwise, at least one character is read and + * stored into {@code cbuf}. * - * @return The number of characters read, or -1 if the end of the - * stream has been reached + * @param cbuf {@inheritDoc} + * @param off {@inheritDoc} + * @param len {@inheritDoc} * - * @throws IOException If an I/O error occurs - * @throws IndexOutOfBoundsException {@inheritDoc} + * @return {@inheritDoc} + * + * @throws IndexOutOfBoundsException {@inheritDoc} + * @throws IOException {@inheritDoc} */ - public int read(char cbuf[], int off, int len) throws IOException { + public int read(char[] cbuf, int off, int len) throws IOException { synchronized (lock) { ensureOpen(); - if ((off < 0) || (off > cbuf.length) || (len < 0) || - ((off + len) > cbuf.length) || ((off + len) < 0)) { - throw new IndexOutOfBoundsException(); - } else if (len == 0) { + Objects.checkFromIndexSize(off, len, cbuf.length); + if (len == 0) { return 0; } if (next >= length) |
