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

default encoding in String(byte[]) doesn't match file.encoding

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.8
    • core-libs



      Name: et89391 Date: 07/22/99



      To execute code, use this command:
      "java -Dfile.encoding=iso-8859-2 ErrorInEncoding":
      ----------------------------------------------------------------
      import java.io.*;
      import java.util.*;

      public class ErrorInEncoding {
       static public void main(String[] args)
          throws UnsupportedEncodingException,IOException
       {
        String smallCzechLetters =
        "a\u00e1bc\u010dd\u010fe\u00e9\u011bfghi\u00edjklmn\u0148o\u00f3pqr\u0159s\u0161t\u0165u\u00fa\u016fvwxy\u00fdz\u017e";
       // get 8-bit chars in iso-8859-2
       byte [] ISO2bytes = smallCzechLetters.getBytes("iso-8859-2");
       // convert them
       String explicit = new String(ISO2bytes,"iso-8859-2");
       String implicit = new String(ISO2bytes);
       // compare them
       System.out.println((smallCzechLetters.equals(explicit)?"Match":"Not match"));
       System.out.println((smallCzechLetters.equals(implicit)?"Match":"Not match"));
       }
      }
      ------------------------------------------------------------------
      This will produce output "Match, Not match", so default encoding
      used in String constructor is not matching the encoding specified
      with -Dfile.encoding.

      This bugs is in SUN JDK1.1.8 on WinNT,
      it is not in IBM JDK1.1.6 on AIX
      and is not in Blackdown.org JDK1.1.7v1a on Linux
      others I haven't tried.
      (Review ID: 63197)
      ======================================================================

            nlindenbsunw Norbert Lindenberg (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: