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

Error in result of String.compareToIgnoreCase

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.1
    • 1.4.0
    • core-libs
    • None
    • hopper
    • x86
    • windows_2000
    • Verified

      Consider the following program:

      public class Test {
          public static void main(String[] args){
              String s1 = "\u00df";
              String s2 = "SS";
              System.out.println(s1.toUpperCase().toLowerCase().compareTo(
                  s2.toUpperCase().toLowerCase()));
              System.out.println(s1.compareToIgnoreCase(s2));
          }
      }

      When running it, the following is reported:

      J:\>java Test
      0
      108

      I.e. two different results are reported, while the API documentation
      states they should be the same.
      This is due to the change applied in 1.4 to String.toUpperCase,
      which translates a German sharp-s into SS, which is correct, but
      invalidates the definition of compareToIgnoreCase().
      Note that this is not an issue of compareToIgnoreCase() delivering
      satisfactory results or not, but of compying to its specification.

            joconnersunw John Oconner (Inactive)
            mzaudousunw Menasse Zaudou (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: