Harmony
  1. Harmony
  2. HARMONY-64

[classlib][nio charset] java.nio.charset.Charset.forName(String name) does not throw UnsupportedCharsetException if valid name starts with "x-"

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None

      Description

      According to j2se 1.4.2 specification for Charset forName(String charsetName) the method must throw UnsupportedCharsetException "if no support for the named charset is available in this instance of the Java virtual machine". The method does not throw exception if a unsupported name started with "x-". For example, the method throws an exception for not supported name "xyz", but does not for "x-yz".

      Code to reproduce:
      import java.nio.charset.*;

      public class test2 {
      public static void main (String[] args) {
      try

      { Charset ch=Charset.forName("x-yz"); System.out.println("***BAD. UnsupportedCharsetException must be thrown instead of creating "+ch); }

      catch (UnsupportedCharsetException e)

      { System.out.println("***OK. Expected UnsupportedCharsetException " + e); }

      }
      }
      Steps to Reproduce:
      1. Build Harmony (check-out on 2006-01-30) j2se subset as described in README.txt.
      2. Compile test2.java using BEA 1.4 javac
      > javac -d . test2.java
      3. Run java using compatible VM (J9)
      > java -showversion test2

      Output:
      C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2
      java version "1.4.2_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
      BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, Native Threads, GC strategy: parallel)
      ***OK. Expected UnsupportedCharsetException java.nio.charset.UnsupportedCharsetException: x-yz

      C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2
      (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable.
      ***BAD. UnsupportedCharsetException must be thrown instead of creating Charset[x-yz]

      Suggested junit test case:
      ------------------------ CharsetTest.java -------------------------------------------------
      import java.nio.charset.*;
      import junit.framework.*;

      public class CharsetTest extends TestCase {
      public static void main(String[] args)

      { junit.textui.TestRunner.run(CharsetTest.class); }


      public void test_forName() {
      try

      { Charset ch=Charset.forName("x-yz"); fail("Assert 0: UnsupportedCharsetException must be thrown instead of creating: " + ch); }

      catch (UnsupportedCharsetException e) {
      }
      }
      }

      1. ICUInterface34.dll
        88 kB
        Richard Liang
      2. libICUInterface34.so
        32 kB
        Richard Liang

        Activity

        Hide
        Tim Ellison added a comment -

        This behaviour originates from the ICU provider code, I'll see what they say about it first:
        http://bugs.icu-project.org/cgi-bin/icu-bugs/incoming?findid=5027

        Show
        Tim Ellison added a comment - This behaviour originates from the ICU provider code, I'll see what they say about it first: http://bugs.icu-project.org/cgi-bin/icu-bugs/incoming?findid=5027
        Hide
        Richard Liang added a comment -

        ICU team has fixed this bug. Here are the libraries I build from icu4jni's latest code.

        Show
        Richard Liang added a comment - ICU team has fixed this bug. Here are the libraries I build from icu4jni's latest code.
        Hide
        Tim Ellison added a comment -

        Richard,

        When you say "icu4jni's latest code" can you be more specific? Was this HEAD or a release ... ?
        We need to know exactly what it contains before deciding whether to use it.

        Thanks,
        Tim

        Show
        Tim Ellison added a comment - Richard, When you say "icu4jni's latest code" can you be more specific? Was this HEAD or a release ... ? We need to know exactly what it contains before deciding whether to use it. Thanks, Tim
        Hide
        Tim Ellison added a comment -

        Svetlana,

        We have decided to defer this fix until the next official release of ICU4JNI becomes available. Let us know if this is a problem.

        Thanks
        Tim

        Show
        Tim Ellison added a comment - Svetlana, We have decided to defer this fix until the next official release of ICU4JNI becomes available. Let us know if this is a problem. Thanks Tim
        Hide
        Svetlana Samoilenko added a comment -

        Tim, I have no objection. Let's wait.

        Show
        Svetlana Samoilenko added a comment - Tim, I have no objection. Let's wait.
        Hide
        Tony Wu added a comment -

        I verified that it has been fixed in icu4jni3.6.
        Would you please close it?

        Show
        Tony Wu added a comment - I verified that it has been fixed in icu4jni3.6. Would you please close it?
        Hide
        Tim Ellison added a comment -

        Was fixed in later version of ICU.

        Show
        Tim Ellison added a comment - Was fixed in later version of ICU.

          People

          • Assignee:
            Tim Ellison
            Reporter:
            Svetlana Samoilenko
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development