Summary
I propose to change the implementation of java.util.Scanner's constructor from using StringReader to using Reader.of(String).
Problem
Scanner's JavaDocs explicitly claim that Scanner is not synchronized:
* <p>A {@code Scanner} is not safe for multithreaded use without
* external synchronization.
Compared to the non-synchronized Reader.of(String) implementation, StringReader's implementation could be potentially less efficient, as it is synchronized.
Solution
public Scanner(String source) {
this(Reader.of(source), WHITESPACE_PATTERN);
}
Specification
The specification of java.util.Scanner is not modified.
- csr of
-
JDK-8377388 Replacing "new StringReader(String)" by "Reader.of(CharSequence);" in Scanner
-
- In Progress
-