On Tue, 27 Apr 2021 18:47:41 GMT, Brian Burkhalter <b...@openjdk.org> wrote:
> Please consider this request to modify `Reader.read(CharBuffer)` to check > whether the buffer is read-only before reading any characters from the > character stream. This can happen now if the buffer is read-only. Character > are first read thereby advancing the stream before an attempt is made to put > them in the `CharBuffer` thus incorrectly advancing the stream position. src/java.base/share/classes/java/io/Reader.java line 202: > 200: if (target.isReadOnly()) > 201: throw new ReadOnlyBufferException(); > 202: int len = target.remaining(); It seems like the other branch of the if should also check for read-only and throw. Or can the target not have an array if it is readonly. It might return -1 for a readonly target if the source was used up. The always throw. Moving the `if (target.isReadOnly())` to the line 188: would be unambiguous. test/jdk/java/io/Reader/ReadIntoReadOnlyBuffer.java line 52: > 50: try { > 51: r.read(b); > 52: throw new RuntimeException(); A helpful message would make it clearer what failed, when/if it fails. ------------- PR: https://git.openjdk.java.net/jdk/pull/3725