RFR: 8341566: Adding factory for non-synchronized CharSequence Reader [v4]

Alan Bateman alanb at openjdk.org
Tue Oct 8 13:26:01 UTC 2024


On Tue, 8 Oct 2024 12:58:17 GMT, Chen Liang <liach at openjdk.org> wrote:

>>>  I cannot image any scenario where such a program would result in useful outcome.
>> 
>> An additional point of reference is the current default implementation of CharSequence's `public default IntStream chars()`, which returns an IntStream of char values from the sequence and the implementation of which doesn't consider the `length()` to be fixed.
>
> For `chars()` or `codePoints()`, I believe calling `length()` or not was a matter of implementation convenience instead of the assumption that `length()` can change during calls. Note implementation methods in the anonymous class in `codePoints()` cache the length in local variables. Maybe they just don't want the extra field overhead in the objects they construct.

> @AlanBateman WDYT?

It's good question as a CharSequence's length can change over time, e.g. StringBuilder. This scenario comes up regularly with InputStreams and Readers connected to files as the file may be growing and shrinking as bytes are read. It would not be surprising to read to EOF/-1 and to not read any further chars, even if the underlying sequence has grow.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21371#discussion_r1791870741


More information about the core-libs-dev mailing list