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

(cs) ebcdic charset names rejected by Charset.forName

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 5.0
    • core-libs
    • b35
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.5.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
      Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Windows XP SP2 Version 2002

      A DESCRIPTION OF THE PROBLEM :
      The IANA name "ebcdic-cp-us" passed as charset name to Charset.forName() causes a throw of IllegalCharsetNameException. This name is of legal form, and in fact should be a supported charset name.

      What I've discovered is that prefixing this name with "cs-" causes the system to find the charset. However "cs-ebcdic-cp-us" is not a standard IANA alias for this charset. I don't mind having this additional non-standard name be accepted as an alias, but the official alias "ebcdic-cp-us" should certainly be accepted, and well-formed names shouldn't throw "IllegalCharsetNameException" rather they should throw "UnsupportedCharsetException".

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Make sure charsets.jar is on the classpath or neither of these will find the character set.

      Charset.forName("ebcdic-cp-us");

      Charset.forName("cs-ebcdic-cp-us");

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Charset.forName("ebcdic-cp-us"); // should not throw IllegalCharsetNameException


      ACTUAL -
      Charset.forName("ebcdic-cp-us"); // throws IllegalCharsetNameException

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package com.ascential;
      import java.util.*;

      import java.nio.charset.Charset;


      // JUNIT & JDEPEND
      import junit.framework.*;

      public class testCharsets extends TestCase {
        public testCharsets(String a_name) { super(a_name); }

        public static Test suite() { return new TestSuite(testCharsets.class); }
        public void setUp() throws Exception { super.setUp(); }
        protected void tearDown() throws Exception { super.tearDown(); }

        public void testCharsets1() throws Exception {

          Charset ebcdic = Charset.forName("ebcdic-cp-us");
          assertNotNull(ebcdic);
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      You can work around this by catching the exception and retrying with "cs-" prefix on any charset name that throws. Ugly and annoying to have to discover and work out, but it works.
      ###@###.### 2005-04-13 06:19:56 GMT

            sherman Xueming Shen
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: