JDK-8377388 - Replacing "new StringReader(String)" by "Reader.of(CharSequence);" in Scanner

Alan Bateman alan.bateman at oracle.com
Mon Feb 9 08:11:54 UTC 2026


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