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

Wrong decoding results for code page 50220

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_92"
      Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

      Tried latest 1.8.0 also.

      A DESCRIPTION OF THE PROBLEM :
      Decoding a byte array to a string using the charset "MS50220" fails to decode some characters which the real Microsoft code page 50220 can decode.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test program.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should print:



      If there is any doubt, here is the equivalent program written in C#, and you can run it here:
      https://dotnetfiddle.net/zDmDiG

      namespace test
      {
      class MainClass
      {
      public static void Main(string[] args)
      {
      byte[] data = { 0x1B, 0x24, 0x42, 0x7B, 0x7D, 0x1B, 0x28, 0x42 };
      string str = System.Text.Encoding.GetEncoding(50220).GetString(data);
      System.Console.WriteLine(str);
      }
      }
      }

      ACTUAL -
      Actually prints what looks like nothing, but it seems to be a special character.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class Test
      {
          public static void main(String[] args) throws Exception
          {
              byte[] data = { 0x1B, 0x24, 0x42, 0x7B, 0x7D, 0x1B, 0x28, 0x42 };
              String str = new String(data, "MS50220");
              System.out.println(str);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use "x-windows-iso2022jp" instead of "MS50220" . But easier said than done when the code page declaration is inside a file parsed by someone else's code.

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

              Created:
              Updated:
              Resolved: