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

Markus KARG duke at openjdk.org
Tue Oct 8 11:29:02 UTC 2024


On Mon, 7 Oct 2024 04:44:43 GMT, Chen Liang <liach at openjdk.org> wrote:

>> src/java.base/share/classes/java/io/Reader.java line 172:
>> 
>>> 170:         Objects.requireNonNull(source);
>>> 171: 
>>> 172:         return new Reader() {
>> 
>> Maybe make this into a package‑private `CharSequenceReader` so that [`StringReader​::close()`] doesn’t have to use a try‑catch.
>> 
>> [`StringReader​::close()`]: https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/io/StringReader.html#close()
>
> I don't think that try-catch is too much of a bloat compared to the extra license header and imports from the explicit `CharSequenceReader.java` file.

> Maybe make this into a package‑private `CharSequenceReader` so that [`StringReader​::close()`](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/io/StringReader.html#close()) doesn’t have to use a try‑catch.

This is exactly the opposite of what Alan and me had in mind: It piles up the stack of special-case classes. Instead, I do agree with Chen regarding code bloat.

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

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


More information about the core-libs-dev mailing list