<i18n dev> RFR: 8274544: Langtools command's usage were garbled on Japanese Windows [v3]

Ichiroh Takiguchi itakiguchi at openjdk.java.net
Wed Oct 13 18:11:49 UTC 2021


On Fri, 8 Oct 2021 21:07:32 GMT, Naoto Sato <naoto at 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
>
> BTW, does the PoC in the jshell bug report really causing the issue?
> 
> System.out.println("\u3042")
> 
> This is ASCII, so save/restore does not seem to cause any issues across JDKs with and without JEP400. Did you mean `Systemout.println("あ")` instead?

Hello @naotoj .
Sorry I'm late.

I'd like to show you jshell issue step by step.
1. `System.out.println(...)` did not work if non-ASCII character was printed on JDK18-b13.
Because jshell output encoding was MS932, jshell agent output encoding was UTF-8
![jshell-932-01](https://user-images.githubusercontent.com/33543753/137185670-02bcec50-d5af-4515-b16b-2893094732d5.png)

2. Above fix was applied against `JShellToolProvider.java` only.
The issue was not fixed.
![jshell-932-02](https://user-images.githubusercontent.com/33543753/137186394-2c8bab09-7889-42d4-bbb7-2fb7b8a86a80.png)

3. Just applied lahodaj's fix `JShellToolBuilder.java`.
It worked fine as expected
![jshell-932-03](https://user-images.githubusercontent.com/33543753/137187148-d1eb0821-599a-4c27-a739-434ed21ff5b6.png)

4. I checked compatibility between JDK17 and this fix by using `/save` and `/open`
It seemed saved a.jsh's encoding was MS932
![jshell-932-04](https://user-images.githubusercontent.com/33543753/137187671-b271a772-790d-4925-aa84-dc003e904c34.png)

5. I think jshell and agent should use same `file.encoding` system property. I applied following fix.

--- a/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiInitiator.java
+++ b/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiInitiator.java
@@ -27,6 +27,7 @@ package jdk.jshell.execution;
 import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
+import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -86,6 +87,17 @@ public class JdiInitiator {
             Map<String, String> customConnectorArgs) {
         this.remoteAgent = remoteAgent;
         this.connectTimeout = (int) (timeout * CONNECT_TIMEOUT_FACTOR);
+        if (!StandardCharsets.UTF_8.equals(Charset.defaultCharset())) {
+            boolean encodingFlag = true;
+            for (String s : remoteVMOptions.toArray(new String[0])) {
+                if (s.startsWith("-Dfile.encoding="))
+                    encodingFlag = false;
+            }
+            if (encodingFlag) {
+                remoteVMOptions.add("-Dfile.encoding="
+                    +Charset.defaultCharset().name());
+            }
+        }
         String connectorName
                 = isLaunch
                         ? "com.sun.jdi.CommandLineLaunch"


![image](https://user-images.githubusercontent.com/33543753/137186123-46ba46cb-e1ac-4a9f-ac77-05c2502cd368.png)

I think `JShellToolBuilder.java` and `JdiInitiator.java`.
Could you give me some suggestions ?

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

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


More information about the i18n-dev mailing list