RFR: 8266078: Reader.read(CharBuffer) advances Reader position for read-only Charbuffers [v2]

Alan Bateman alanb at openjdk.java.net
Wed Apr 28 06:36:57 UTC 2021


On Tue, 27 Apr 2021 20:25:32 GMT, Brian Burkhalter <bpb at 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.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8266078: Make read-only check global; add message in test

Marked as reviewed by alanb (Reviewer).

src/java.base/share/classes/java/io/Reader.java line 206:

> 204:             char[] cbuf = new char[len];
> 205:             // If a read-only check had not been done above, then
> 206:             // the stream would be incorrectly advanced here.

The RO check is good but I'm not sure that this comment is useful (it might confuse future maintainers), I would be tempted to leave that part out.

-------------

PR: https://git.openjdk.java.net/jdk/pull/3725


More information about the core-libs-dev mailing list