RFR: 8357996: Use "stdin.encoding" for reading System.in with InputStreamReader/Scanner [tools] [v3]

Naoto Sato naoto at openjdk.org
Thu Jun 12 19:18:33 UTC 2025


On Fri, 6 Jun 2025 07:08:28 GMT, Volkan Yazici <vyazici at openjdk.org> wrote:

>> Passes the `Charset` read from the `stdin.encoding` system property while creating `InputStreamReader` or `Scanner` instances for `System.in`.
>> 
>> `stdin.encoding` is a recently added property for Java 25 in [JDK-8350703](https://bugs.openjdk.org/browse/JDK-8350703). Employing it throughout the entire code base is addressed by the parent ticket [JDK-8356893](https://bugs.openjdk.org/browse/JDK-8356893). JDK-8357996 this PR is addressing is a sub-task of JDK-8356893 and is concerned with only areas related to tools.
>
> Volkan Yazici has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains seven commits:
> 
>  - Merge remote-tracking branch 'upstream/master' into stdinEnc-build
>  - Provide fallback for `stdin.encoding` in `ExternalEditor`
>  - Discard changes unrelated with build and tools
>  - Revert superfluous changes
>    
>    Remove assertion in `DOMImplementationRegistry`
>  - Revert changes to 3rd parties in `com/sun/org/apache`
>  - Revert `PandocFilter` changes
>    
>    `PandocFilter` et al. gets called using the boot JDK,
>    which doesn't have `stdin.encoding` yet.
>  - Use `stdin.encoding` in `InputStreamReader` and `Scanner` instantiations
>    
>    Improve `CharsetTest`

src/jdk.internal.ed/share/classes/jdk/internal/editor/external/ExternalEditor.java line 170:

> 168:                 // -wait option -- ignore process exit, wait for carriage-return
> 169:                 Charset charset = Charset.forName(System.getProperty("stdin.encoding"), Charset.defaultCharset());
> 170:                 Scanner scanner = new Scanner(System.in, charset);

I think the code is simply expecting a CR, so this change may not be needed.

test/langtools/jdk/jshell/CompletenessTest.java line 103:

> 101:         "final Deque<Token> stack = new ArrayDeque<>()",
> 102:         "java.util.Scanner input = new java.util.Scanner(System.in, System.getProperty(\"stdin.encoding\"))",
> 103:         "java.util.Scanner input = new java.util.Scanner(System.in, System.getProperty(\"stdin.encoding\")) { }",

These seem to be checking a unit is complete or not, so these changes may be irrelevant too.

test/langtools/jdk/jshell/UserInputTest.java line 50:

> 48:     public void testScanner() {
> 49:         assertEval("import java.util.Scanner;");
> 50:         assertEval("Scanner s = new Scanner(System.in, System.getProperty(\"stdin.encoding\"));");

JShell's `System.in` is not a real `System.in` (set by `JShell.builder().in()`), so I think this one is not necessary either

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25541#discussion_r2143422630
PR Review Comment: https://git.openjdk.org/jdk/pull/25541#discussion_r2143427913
PR Review Comment: https://git.openjdk.org/jdk/pull/25541#discussion_r2143447300


More information about the kulla-dev mailing list