JDK-8377388 - Replacing "new StringReader(String)" by "Reader.of(CharSequence);" in Scanner
Markus KARG
markus at headcrashing.eu
Mon Feb 9 12:08:48 UTC 2026
Thank you, Alan and Chen!
As two committers affirmed, I now have opened the pull request:
https://github.com/openjdk/jdk/pull/29627
Kindly inviting everybody to review it.
Regards
-Markus
Am 09.02.2026 um 09:11 schrieb Alan Bateman:
> On 08/02/2026 14:08, Markus KARG wrote:
>> Core-Lib Devs,
>>
>> as proposed in https://bugs.openjdk.org/browse/JDK-8377388 I would
>> like to replace "new StringReader(String)" by
>> "Reader.of(CharSequence);" in java.util.Scanner, which seems to be
>> safe and simple:
>>
>> * There is no actual need for the synchronization found in
>> StringReader, as Scanner itself is explicitly *not* synchronized, no
>> code depends on StringReader in partiular, and the reader is not leaked.
>
> Async close is one area where StringReader and the Reader returned by
> Reader.of(cs) have different behavior. At the same time Scanner is
> specified to not be thread safe. So on the surface, I think it should
> be okay, and anything relying on concurrent usage or async close of a
> Scanner may already broken if it doesn't use external synchronization.
> I think the compatibility impact for the CSR will be low.
>
> -Alan
More information about the core-libs-dev
mailing list