Hi Mark,
I think this patch should be simple enough to prove it has no unexpected 
impacts.
The reader becomes the source field, which is only used in Scanner.readInput 
apart from closing; readInput uses buf in a non-thread-safe way, so I think it 
is reasonable for readInput to operate on a non-thread-safe source too.
In addition, now StringReader is just a synchronized wrapper of Reader.of. So 
there should be minimal impact from this change.

Regards,
Chen Liang
________________________________
From: core-libs-dev <[email protected]> on behalf of Markus KARG 
<[email protected]>
Sent: Sunday, February 8, 2026 8:08 AM
To: 'core-libs-dev' <[email protected]>
Subject: JDK-8377388 - Replacing "new StringReader(String)" by 
"Reader.of(CharSequence);" in Scanner

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.

Alan, Chen and Jaikiran were already active in the JIRA ticket.

I have meanwhile coded the change (see diff at
https://github.com/mkarg/jdk/commit/03837bb46aeb4c907af0fef8063f461aceaf079a)
and tested it successfully using OpenJDK Github Actions (see result at
https://github.com/mkarg/jdk/actions/runs/21787869983).

Are you fine with me opening a Pull Request on Github?

Thanks!

-Markus

Reply via email to