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

(cs) Charset.forName() doesn't throw IllegalCharsetNameException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 5.0
    • core-libs
    • sparc
    • solaris_8



      Name: auR10023 Date: 03/14/2003



      Javadoc for java.nio.charset.Charset says:
      ...
       The empty string is not a legal charset name.
      ...
      So, java.nio.charset.Charset.forName(String) should throw
      IllegalCharsetNameException with empty string.

      Here is the example:

      -------test.java---------
      import java.nio.charset.*;

      public class test {
          public static void main (String [] args) {
              try {
                  Charset.forName("");
                  System.out.println("IllegalCharsetNameException expected");
                  return;
              } catch(IllegalCharsetNameException e) { } catch (UnsupportedCharsetException e) {
                  System.out.println("Unexpected " + e);
                  return;
              }
              System.out.println("OKAY");
          }
      }

      Here is the result
      #java -version

      java version "1.4.2-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b16)
      Java HotSpot(TM) Client VM (build 1.4.2-beta-b16, mixed mode)

      #java test

      Unexpected java.nio.charset.UnsupportedCharsetException:

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

            iris Iris Clark
            avusunw Avu Avu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: