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

java.text.Collator.compare() broken ('AAA - ...' < 'A - ...')

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Win 6.1.7601

      A DESCRIPTION OF THE PROBLEM :
      Collator collator = Collator.getInstance(Locale.US);
      int comp = collator.compare("AAA - Vorschalldampfer", "A - Abgasanlagen");
      int compNoSpace = collator.compare("AAA", "A");

      And now comp is -1. Interestingly, compNoSpace is 1.

      This looks very similar to the issue described in https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4065540 , but the latter has been closed over 20 years ago as no longer reproducible.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Simply run the code in the description above.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      collator.compare("AAA - Vorschalldampfer", "A - Abgasanlagen") == -1;
      ACTUAL -
      collator.compare("AAA - Vorschalldampfer", "A - Abgasanlagen") == 1;

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Not applicable.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Collator collator = Collator.getInstance(Locale.US);
      int comp = collator.compare("AAA - Vorschalldampfer", "A - Abgasanlagen");
      System.out.println("Comparison with spaces = " + comp);
      int compNoSpace = collator.compare("AAA", "A");
      System.out.println("Comparison without spaces = " + compNoSpace);

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use java.lang.String natural ordering, but that doesn't produce the correct result in all cases and applications.

        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: