<i18n dev> RFR: 8274544: Langtools command's usage were grabled on Japanese Windows

Ichiroh Takiguchi itakiguchi at openjdk.java.net
Fri Oct 1 02:07:41 UTC 2021


On Thu, 30 Sep 2021 21:45:15 GMT, Naoto Sato <naoto at openjdk.org> wrote:

>> Screenshot
>> ![javac-screenshot](https://user-images.githubusercontent.com/33543753/135429041-0ed22b36-0b1e-4626-92ca-8b58acf8872d.png)
>> 
>> javac does not use PrintStream for standard out/err, it uses PrintWriter.
>> I put some codes on src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java
>> * Using native.encoding system property. But test/langtools/tools/javac/diags/CheckResourceKeys.java was failed.
>> * Use java.io.Console, like Console cons = System.console() and cons.charset(), but "javac 2>&1 | more" does not work as expected because System.console() returns null.
>> 
>> So I added -Dfile.encoding=COMPAT expect java and javaw commands on launcher.
>> 
>> jshell does not work as expected on b12
>> 
>>>jdk-18-b12\bin\jshell.exe
>> |  JShellへようこそ -- バージョン18-ea
>> |  概要については、次を入力してください: /help intro
>> 
>> jshell> "\u3042".getBytes()
>> $1 ==> byte[2] { -126, -96 }
>> 
>> on b13
>> 
>>>jdk-18-b13\bin\jshell.exe
>> |  JShellへようこそ -- バージョン18-ea
>> |  概要については、次を入力してください: /help intro
>> 
>> jshell> "\u3042".getBytes()
>> $1 ==> byte[3] { -29, -127, -126 }
>> 
>> It's UTF-8, not native encoding.
>> I think backend java process should use same fine.encoding system property setting.
>> 
>> I don't think it's good fix, so please give me some advices.
>
>> * Using native.encoding system property. But test/langtools/tools/javac/diags/CheckResourceKeys.java was failed.
> 
> What was the cause of the failure?
> 
>> * Use java.io.Console, like Console cons = System.console() and cons.charset(), but "javac 2>&1 | more" does not work as expected because System.console() returns null.
>> 
>> So I added -Dfile.encoding=COMPAT expect java and javaw commands on launcher.
> 
> I think we should fix the root cause of this, instead of specifying `file.encoding=COMPAT`
> 
>> 
>> jshell does not work as expected on b12
> 
> Do you mean `b13`?
> 
>> 
>> ```
>> >jdk-18-b12\bin\jshell.exe
>> |  JShellへようこそ -- バージョン18-ea
>> |  概要については、次を入力してください: /help intro
>> 
>> jshell> "\u3042".getBytes()
>> $1 ==> byte[2] { -126, -96 }
>> ```
>> 
>> on b13
>> 
>> ```
>> >jdk-18-b13\bin\jshell.exe
>> |  JShellへようこそ -- バージョン18-ea
>> |  概要については、次を入力してください: /help intro
>> 
>> jshell> "\u3042".getBytes()
>> $1 ==> byte[3] { -29, -127, -126 }
>> ```
>> 
>> It's UTF-8, not native encoding. I think backend java process should use same fine.encoding system property setting.
> 
> No it should not. `file.encoding` should not be inherited.
> 
> Naoto

@naotoj 
I applied following change on src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java

--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java
@@ -26,6 +26,7 @@
 package com.sun.tools.javac.util;

 import java.io.*;
+import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.EnumMap;
 import java.util.EnumSet;
@@ -261,12 +262,22 @@ public class Log extends AbstractLog {
      * @param context the context in which to find writers to use
      * @return a map of writers
      */
+    private final static Charset nativeCharset;
+    static {
+        Charset cs = Charset.defaultCharset();
+        try {
+            cs = Charset.forName(System.getProperty("native.encoding"));
+        } catch (Exception e) {
+        }
+        nativeCharset = cs;
+    }
+
     private static Map<WriterKind, PrintWriter> initWriters(Context context) {
         PrintWriter out = context.get(outKey);
         PrintWriter err = context.get(errKey);
         if (out == null && err == null) {
-            out = new PrintWriter(System.out, true);
-            err = new PrintWriter(System.err, true);
+            out = new PrintWriter(System.out, true, nativeCharset);
+            err = new PrintWriter(System.err, true, nativeCharset);
             return initWriters(out, err);
         } else if (out == null || err == null) {
             PrintWriter pw = (out != null) ? out : err;


I got following exception via tools/javac/diags/CheckResourceKeys.java

Error: no match for "native.encoding"
java.lang.Exception: 1 errors occurred
        at CheckResourceKeys.main(CheckResourceKeys.java:59)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127)
        at java.base/java.lang.Thread.run(Thread.java:833)

About jshell, my sample was not good,
See this one.
By b12

>jdk-18-b12\bin\jshell
|  JShellへようこそ -- バージョン18-ea
|  概要については、次を入力してください: /help intro

jshell> System.out.println("\u3042")
あ

By b13

>jdk-18-b13\bin\jshell
|  JShellへようこそ -- バージョン18-ea
|  概要については、次を入力してください: /help intro

jshell> System.out.println("\u3042")
縺・

By b13 with file.encoding=COMPAT

>jdk-18-b13\bin\jshell -J-Dfile.encoding=COMPAT
|  JShellへようこそ -- バージョン18-ea
|  概要については、次を入力してください: /help intro

jshell> System.out.println("\u3042")
縺・

If I need to create another issue, please let me know.

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

PR: https://git.openjdk.java.net/jdk/pull/5771


More information about the i18n-dev mailing list