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

[Ch] Doc: java.lang.Character.digit documentation unclear regarding fullwidth characters

XMLWordPrintable

    • b138
    • generic, x86
    • generic, linux
    • Not verified

      Name: gm110360 Date: 07/15/2002


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


      FULL OPERATING SYSTEM VERSION :
      suse linux 7.3

      A DESCRIPTION OF THE PROBLEM :
      The documenatation for digit is insufficient. It does not
      describe behaviour on fullwidth latin characters, like
      getNumericalValue does.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Read the API for java.lang.Character.digit
      2. Read the API for java.lang.Character.getNumericalValue
      3. Realize there is a divergence

      This bug can be reproduced always.
      (Review ID: 146953)
      ======================================================================
      Due to this CR the current behaviour of Character.digit(int/char, int) contradicts to the specification.
      The following test is based on the specification and fails for full width latin characters variants:
      -----------------------------------------------------------------
      public class DigitMiniTest {
          public static void main(String[] args) {
              int radix = 11;

              for (int cp = 0; cp <= Character.MAX_VALUE; cp++) {
                  int result = Character.digit(cp, radix);
                  int expected = -1;

                  if (Character.isDigit(cp)) {
                      expected = Character.getNumericValue(cp);

                      if (expected >= radix) {
                          expected = -1;
                      }
                  } else if ('a' <= cp && cp <= 'z' && cp < (radix + 'a' - 10)) {
                      expected = cp - 'a' + 10;
                  } else if ('A' <= cp && cp <= 'Z' && cp < (radix + 'A' - 10)) {
                      expected = cp - 'A' + 10;
                  }
                  
                  if (result != expected) {
                      System.out.println("Invalid value: " + result + " instead of "
                              + expected + " for 0x" + Integer.toHexString(cp));
                  }
              }
          }
      };
      -----------------------------------------------------------------
      The output is:
      Invalid value: 10 instead of -1 for 0xff21
      Invalid value: 10 instead of -1 for 0xff41
      -----------------------------------------------------------------

            peytoia Yuka Kamiya (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: