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

java.text.CollationKey.equals() method doesn't work

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.6
    • CPU:
      generic, sparc
    • OS:
      solaris_2.4, solaris_2.5
    • Verification:
      Verified

      Backports

        Description



        Name: mgC56079 Date: 09/11/97



        This method is broken: it may return false for the equal keys.
        CollationKey.compareTo() method doesn't have this bug.

        --------------Here is the method's source ------------------------
            public boolean equals(Object target) {
                if (this == target) return true;
                if (target == null || !getClass().equals(target.getClass())) {
                    return false;
                }
                CollationKey other = (CollationKey)target;
                return key.equals(other.toString()); <--!!! The bug is here: toString()
                                                        !!! method is not defined in
                                                        !!! the CollationKey class.
            }


        ---------Here is the test demonstrating the bug (CKTest.java) --------------

        import java.text.*;

        public class CKTest {
          public static void main(String args[]) {
            RuleBasedCollator en_USCollator = (RuleBasedCollator)
                Collator.getInstance(java.util.Locale.US);
            CollationKey ck1=en_USCollator.getCollationKey("a String");
            CollationKey ck2=en_USCollator.getCollationKey("a String");

            System.out.println("compare: "+ck1.compareTo(ck2));
            System.out.println("equals: "+ck1.equals(ck2));
          }
        }
        ---------Output from the test---------------------
        % java CKTest
        compare: 0
        equals: false

        --------------------------------------------------

        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                bcbeck Brian Beck (Inactive)
                Reporter:
                mgorshen Mikhail Gorshenev (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: