Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8200243

System error message is decoded as invalid encoding in Windows.

XMLWordPrintable

    • 9
    • b20
    • x86_64
    • windows_10
    • Not verified

        FULL PRODUCT VERSION :
        java version "9.0.4"
        Java(TM) SE Runtime Environment (build 9.0.4+11)
        Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

        Also,
        java version "10" 2018-03-20
        Java(TM) SE Runtime Environment 18.3 (build 10+46)
        Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 10.0.16299.309]

        A DESCRIPTION OF THE PROBLEM :
        In Japanese environment, error messages by Windows
        (e.g. "確立された接続がホスト コンピューターのソウトウェアによって中止されました。",
        in English: "An established connection was aborted by the software in your host machine.")
        are decoded as wrong encoding. This causes mojibake, and users can't understand the error message.

        It seems that the original messages are in UTF-8 but they are decoded as CP932(Shift-JIS).

        REGRESSION. Last worked in version 8u162

        ADDITIONAL REGRESSION INFORMATION:
        In jre1.8.0_162, error messages are decoded correctly.

        java version "1.8.0_162"
        Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
        Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Cause IOException with nio object.
        Then, get error message from the exception with getMessage() or getLocalizedMessage().
        Example: attached source code.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Output:
        ----------------------------
        確立された接続がホスト コンピューターのソウトウェアによって中止されました。
        確立された接続がホスト コンピューターのソウトウェアによって中止されました。
        false
        true
        ----------------------------
        or
        ----------------------------
        An established connection was aborted by the software in your host machine.
        確立された接続がホスト コンピューターのソウトウェアによって中止されました。
        false
        true
        ----------------------------
        ACTUAL -
        Output:
        ----------------------------
        遒コ遶九&繧後◆謗・邯壹′繝帙せ繝? 繧ウ繝ウ繝斐Η繝シ繧ソ繝シ縺ョ繧ス繧ヲ繝医え繧ァ繧「縺ォ繧医▲縺ヲ荳ュ豁「縺輔l縺セ縺励◆縲?
        遒コ遶九&繧後◆謗・邯壹′繝帙せ繝? 繧ウ繝ウ繝斐Η繝シ繧ソ繝シ縺ョ繧ス繧ヲ繝医え繧ァ繧「縺ォ繧医▲縺ヲ荳ュ豁「縺輔l縺セ縺励◆縲?
        true
        false
        ----------------------------

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.io.*;
        import java.net.*;
        import java.nio.*;
        import java.nio.channels.*;

        public class Test {
            public static void main(String[] args) throws IOException {
                int port = 12345;
                ServerSocket server = new ServerSocket(port);
                new Thread(() -> {
                    try
                    {
                        server.accept().close(); // socket close imediately
                    }
                    catch (IOException e)
                    {
                    }
                }).start();
                
                try {
                    SocketChannel channel = SocketChannel.open(new InetSocketAddress("localhost", port));
                    Thread.sleep(1000);
                    // write data to the closed connection
                    for (int i = 0; i < 100; i++)
                        channel.write(ByteBuffer.wrap("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n".getBytes()));
                } catch (InterruptedException|IOException e) {
                    System.out.println(e.getMessage());
                    System.out.println(e.getLocalizedMessage());
                    String msg = e.getLocalizedMessage();
                    System.out.println(msg.startsWith("遒コ")); // mojibake, should be false
                    System.out.println(msg.startsWith("確立された接続が")); // japanese message, should be true
                }
                server.close();
            }
        }
        ---------- END SOURCE ----------

          1. JI9053111.java
            1 kB
          2. Screen8u152.JPG
            Screen8u152.JPG
            25 kB
          3. ScreenJDK10.JPG
            ScreenJDK10.JPG
            32 kB

              sherman Xueming Shen
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: