JDK-8297288 : Example code in Scanner class
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-11-18
  • Updated: 2022-12-19
  • Resolved: 2022-12-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20 JDK 21
20 b28Fixed 21Fixed
Related Reports
Blocks :  
Description
There is one using `System.in` as:
```
     Scanner sc = new Scanner(System.in);
```
With JEP 400, the default charset and console charset may differ, thus this example may result in an unexpected one if the user tries to read a String from the scanner. This should be replaced with:
```
    Scanner sc = new Scanner(Console.reader())
```
so that the user would not have to take encoding into consideration.
Comments
Changeset: 0267aa52 Author: Naoto Sato <naoto@openjdk.org> Date: 2022-12-12 17:59:25 +0000 URL: https://git.openjdk.org/jdk20/commit/0267aa528b83be9914fee4bea8f548b8404b31f8
12-12-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk20/pull/14 Date: 2022-12-09 18:32:37 +0000
09-12-2022