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

(cs) jdk1.4.0beta-b54 java.lang.String: getBytes("ASCII") returns wrong array of

    XMLWordPrintable

Details

    • generic
    • generic

    Description



      Name: ooR10006 Date: 03/11/2001


      jdk1.4.0beta-b54 API implementation, class java.lang.String, method getBytes("ASCII")
      returns wrong array of bytes for the string which contains non-mappable according to
      ASCII charset characters,
      for the string "str\u00EA\u00FF\u00DD\u00BF\u00C1\u00A0" it returns array of
      length 6:
      (byte)115 (byte)116 (byte)114 (byte)63 (byte)63 (byte)63

      jdk1.3.0fcsC returns array of length 9 with all non-mappable chars substituted
      with '?' (int decimal value 63).
      (byte)115 (byte)116 (byte)114 (byte)63 (byte)63 (byte)63 (byte)63 (byte)63 (byte)63

      The following example shows this:


      import java.io.UnsupportedEncodingException;

      public class Test {
          public static void main(String[] args){
              String str = "";
              try {
                  byte[] bytes = "str\u00EA\u00FF\u00DD\u00BF\u00C1\u00A0".getBytes("ASCII");
                  for (int i = 0; i < bytes.length; ++i){
                      str += Byte.toString(bytes[i]) + " ";
                  }
                  System.out.println(bytes.length);
                  System.out.println(str);
              } catch (UnsupportedEncodingException ue){
                  System.out.println(ue);
              }
          }
      }
      novo1% jdk1.3.0fcsC/solaris/bin/java Test
      9
      115 116 114 63 63 63 63 63 63
      novo1% jdk1.4.0beta-b54/solsparc/bin/java Test
      6
      115 116 114 63 63 63
      novo1%


      Due to this Merlin JCK test api/java_lang/String/i18n.html#i18nCtorEncodings[String2211]
      fails on the platforms with "ASCII" default charset.


      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              mr Mark Reinhold
              ovosunw Ovo Ovo (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: