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

String/byte[] conversion with encoding CP1147

XMLWordPrintable

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


      ADDITIONAL OS VERSION INFORMATION :
      ubuntu 16.04 LTS
      Linux LIN0125343 4.4.0-64-generic #85-Ubuntu SMP Mon Feb 20 11:50:30 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      We have an JMS message (TEXT), from COBOL, using comp-3.
      We try to get the byte[] from the String, in order to recover our hexa values.

      We have an issue while decoding a byte (0x15) with the Cp1147 encoding.
      The byte is decode as 0x25 instead of 0x15.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Creating a byte array containing the 0x15 value.
      Create string from that byte array, using CP1147.
      Create a second byte array from the string, using C1147.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      We expect the byte to be the same (0x15)
      ACTUAL -
      The byte's value is 0x25.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      @Test
      public void testEncoding1147() throws UnsupportedEncodingException{
      byte[] bytes = new byte[]{ (byte)0x15, (byte) 0x7B };


      printByte(bytes);


      System.out.println("##################################################");


      String strBytes1147 = new String(bytes, "CP1047");
      System.out.println("strByte Cp1147 ["+strBytes1147+"]");
      byte[] bytesDecodes = strBytes1147.getBytes("CP1047");

      printByte(bytesDecodes);

      System.out.println("##################################################");

      Assert.assertEquals("Size of bytes tables not corresponding", bytes.length, bytesDecodes.length);
      for(int i = 0; i < bytes.length; i++ ){
      Assert.assertEquals("byte N° ["+i+"] not matching", bytes[i], bytesDecodes[i]);
      }
      }


      private void printByte(byte[] bytes){
      StringBuilder sb = new StringBuilder();
      for (byte b : bytes) {
          sb.append(String.format("%02X ", b));
      }
      System.out.println(sb.toString());
      }
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved: