Harmony
  1. Harmony
  2. HARMONY-68

java.nio.charset.Charset.isSupported(String charsetName) does not throw IllegalCharsetNameException for spoiled standard sharset name

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None

      Description

      According to j2se 1.4.2 specification for Charset.isSupported(String charsetName) the method must throw IllegalCharsetNameException "if the given charset name is illegal ".
      "Legal charset name must begin with either a letter or a digit.
      The test listed below shows that there is no the exception if to insert "-" or "_" symbols before standard sharset name, for example "-UTF-8" or "_US-ASCII".

      Moreover the method returns "true" in this case.

      BEA also does not throw the exception but returns "false".

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

      public class test2 {
      public static void main (String[] args) {
      // string starts neither a letter nor a digit
      boolean sup=false;
      try

      { sup=Charset.isSupported("-UTF-8"); System.out.println("***BAD. should be exception; sup="+sup); sup=Charset.isSupported("_US-ASCII"); System.out.println("***BAD. should be exception; sup="+sup); }

      catch (IllegalCharsetNameException e)

      { System.out.println("***OK. Expected IllegalCharsetNameException " + 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)
      ***BAD. should be exception; sup=false
      ***BAD. should be exception; sup=false

      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. should be exception; sup=true
      ***BAD. should be exception; sup=true

      Suggested junit test case:
      ------------------------ CharserTest.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_isSupported() {
      boolean sup=false;
      // string starts neither a letter nor a digit
      try

      { sup=Charset.isSupported("-UTF-8"); fail("***BAD. should be exception IllegalCharsetNameException"); }

      catch (IllegalCharsetNameException e)

      { //expected }
      // string starts neither a letter nor a digit
      try{ sup=Charset.isSupported("_US-ASCII"); fail("***BAD. should be exception IllegalCharsetNameException"); } catch (IllegalCharsetNameException e) { //expected }

      }
      }

      1. CharsetTest.java
        0.3 kB
        Svetlana Samoilenko
      2. charset_patch.txt
        8 kB
        Richard Liang

        Activity

        Svetlana Samoilenko created issue -
        Hide
        Richard Liang added a comment -

        Please try my patch according to the spec of Java 5.0

        Show
        Richard Liang added a comment - Please try my patch according to the spec of Java 5.0
        Richard Liang made changes -
        Field Original Value New Value
        Attachment charset_patch.txt [ 12323102 ]
        Hide
        Tim Ellison added a comment -

        The test looks invalid to me. You shoud only expect an java.nio.charset.IllegalCharsetNameException if the name itself contains disallowed characters, and both underscore and dash are permitted.

        The code
        Charset.isSupported("-UTF-8")

        should return false, not throw an exception.

        Show
        Tim Ellison added a comment - The test looks invalid to me. You shoud only expect an java.nio.charset.IllegalCharsetNameException if the name itself contains disallowed characters, and both underscore and dash are permitted. The code Charset.isSupported("-UTF-8") should return false, not throw an exception.
        Hide
        Svetlana Samoilenko added a comment -

        Yes, the test was wrong.
        See attached correct unit test.

        Show
        Svetlana Samoilenko added a comment - Yes, the test was wrong. See attached correct unit test.
        Svetlana Samoilenko made changes -
        Attachment CharsetTest.java [ 12325952 ]
        Hide
        Svetlana Samoilenko added a comment -

        I've double checked Harmony Compatibility Guidelines and change my mind (and eat my words and attached test ). My test complies with the Java specification "Legal charset name must begin with either a letter or a digit". RI shows wrong behavior.

        Show
        Svetlana Samoilenko added a comment - I've double checked Harmony Compatibility Guidelines and change my mind (and eat my words and attached test ). My test complies with the Java specification "Legal charset name must begin with either a letter or a digit". RI shows wrong behavior.
        Hide
        Nathan Beyer added a comment -

        What's the status of this issue? Is there anything that needs to or can be applied to the source (the test case) or is this invalid and can be closed?

        Show
        Nathan Beyer added a comment - What's the status of this issue? Is there anything that needs to or can be applied to the source (the test case) or is this invalid and can be closed?
        Hide
        Svetlana Samoilenko added a comment -

        Nathan,

        This bug is very close with Harmony issue 311.
        The behaviour shared by Harmony and the RI does not comply with the specification.
        Would it be better to close this bug in corresponding way and to file a bug against Sun?

        Show
        Svetlana Samoilenko added a comment - Nathan, This bug is very close with Harmony issue 311. The behaviour shared by Harmony and the RI does not comply with the specification. Would it be better to close this bug in corresponding way and to file a bug against Sun?
        Hide
        Nathan Beyer added a comment -

        I'm going to resolve this as 'won't fix' for the moment. Feel free to open a bug with Sun and we can revisit this later.

        Show
        Nathan Beyer added a comment - I'm going to resolve this as 'won't fix' for the moment. Feel free to open a bug with Sun and we can revisit this later.
        Nathan Beyer made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Svetlana Samoilenko
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development