On Tue, 19 Oct 2021 01:26:35 GMT, Jonathan Gibbons <j...@openjdk.org> wrote:
>> Ichiroh Takiguchi has updated the pull request incrementally with one >> additional commit since the last revision: >> >> 8274544: Langtools command's usage were garbled on Japanese Windows > > This is pretty ugly code to be replicating so many times. > > What if the tools have been run in an environment where `System.out` and > `System.err` have already been redirected in some manner, with > `System.setOut` or `System.setErr`? You should not assume that `System.out` > and `System.err` will always refer to the console. @jonathan-gibbons I appreciate your comment. I'd like to confirm something. > This is pretty ugly code to be replicating so many times. > What if the tools have been run in an environment where `System.out` and > `System.err` have already been redirected in some manner, with > `System.setOut` or `System.setErr`? You should not assume that `System.out` > and `System.err` will always refer to the console. I was confused since the fixed code did not call System.out/System.err directly. I tried following code on Japanese Windows. import java.io.*; import java.nio.charset.*; public class OutputCheck { public static void main(String[] args) throws Exception { String s = "\u3042"; System.out.println("[1]:"+s); PrintStream ps = System.out; System.setOut(new PrintStream(System.out)); System.out.println("[2]:"+s); ps.println("[3]:"+s); System.setOut(new PrintStream(System.out, true, Charset.forName(System.getProperty("native.encoding")))); System.out.println("[4]:"+s); } } Output is: > jdk-18-b14\bin\java OutputCheck.java [1]:あ [2]:縺・ [3]:あ [4]:あ [2] refers default charset (UTF-8) [3] is same as [1] [4] specifies native.encoding system encoding Could you explain more detail ? ------------- PR: https://git.openjdk.java.net/jdk/pull/5771