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

(cs) Charset.availableCharsets and Charset.name provide conflicting canonical na

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta3
    • generic
    • generic

      The Charset.availableCharsets and Charset.name both provide ways to access the canonical names of the available Charsets. In the current implementation, these methods provide conflicting names for almost all available Charsets (windows-1252 is the only Charset where both methods return the same name).

      import java.nio.Charset;
      import java.util.Iterator;

      public class CheckAvailableCharsets {

          public static void main (String[] args) {
          
              Iterator charsetIterator = Charset.availableCharsets().keySet().iterator();
              while (charsetIterator.hasNext()) {
                  String charsetName = (String) charsetIterator.next();
                  Charset charset = Charset.forName(charsetName);
                  if (!charset.name().equals(charsetName)) {
                      System.out.println("Error: Charset name mismatch - expected "
                              + charsetName + ", got " + charset.name());
                  }
              }
          }
      }

      produces:

      Error: Charset name mismatch - expected iso-8859-1, got ISO-8859-1
      Error: Charset name mismatch - expected iso-8859-15, got ISO-8859-15
      Error: Charset name mismatch - expected us-ascii, got US-ASCII
      Error: Charset name mismatch - expected utf-16, got UTF-16
      Error: Charset name mismatch - expected utf-16be, got UTF-16BE
      Error: Charset name mismatch - expected utf-16le, got UTF-16LE
      Error: Charset name mismatch - expected utf-8, got UTF-8

            mr Mark Reinhold
            nlindenbsunw Norbert Lindenberg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: