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

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 25
    • Component/s: core-libs
    • None

      The JavaDocs of java.util.Scanner currently says...

      * <p>A {@code Scanner} is not safe for multithreaded use without
      * external synchronization.

      ...but the source code actually instantiates StringReader...

      public Scanner(String source) {
          this(new StringReader(source), WHITESPACE_PATTERN);
      }

      ...and StringReader *is* synchronized.

      As synchronization is a *non*-target of the Scanner class, and the Scanner does *not* leak the Readable it is reading from, we can safely replace "new StringReader" by "Reader.of(CharSequence);" here, which effectively provides a *non*-synchronized (hence potentially more efficient) Reader.

            Assignee:
            Markus Karg
            Reporter:
            Markus Karg
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: