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

CollationKey doesn't take ignorable strings into account

XMLWordPrintable

    • 1.1.6
    • sparc
    • solaris_2.5.1
    • Verified



        Name: laC46010 Date: 10/19/97



        String comparison using Collator.getCollationKey() and Collator.compare()
        produces different results when compared strings contain ignorable strings.

        For example, Collator.compare() treats the following strings as equal to
        empty string "" :
        "\u200b", "\u200c", "\u200d", "\u200e", "\u200f", "\u0000", "\u0001",
        "\u0002", "\u0003", "\u0004", "\u0005", "\u0006", "\u0007", "\u0008",
        "\u000e", "\u000f", "\u0010", "\u0011", "\u0012", "\u0013", "\u0014",
        "\u0015", "\u0016", "\u0017", "\u0018", "\u0019", "\u001a", "\u001b",
        "\u001c", "\u001d", "\u001e", "\u001f", "\u007f", "\u0080", "\u0081",
        "\u0082", "\u0083", "\u0084", "\u0085", "\u0086", "\u0087", "\u0088",
        "\u0089", "\u008a", "\u008b", "\u008c", "\u008d", "\u008e", "\u008f",
        "\u0090", "\u0091", "\u0092", "\u0093", "\u0094", "\u0095", "\u0096",
        "\u0097", "\u0098", "\u0099", "\u009a", "\u009b", "\u009c", "\u009d",
        "\u009e", "\u009f".

        At the same time Collator.getCollationKey() produces different keys
        for these strings and considers them to be unequal to empty string.

        See also an example below:
        --------------output----------------
        failed:Collator.compare: 0 CollationKey.compareTo: -1

        --------------CollationKey_fails.java--------------------
        import java.util.Locale;
        import java.text.Collator;
        import java.text.CollationKey;

        class CollationKey_fails {

            public static void main(String argv[]) {
        Collator coll = Collator.getInstance(new Locale("en", "US"));
        CollationKey key, key1;

        coll.setStrength(Collator.TERTIARY);
        key = coll.getCollationKey("123");
        key1 = coll.getCollationKey( "123\u008b");
        if (coll.compare("123", "123\u008b") != key.compareTo(key1)) {
        System.out.println("failed:Collator.compare: " +
        coll.compare("", "\u008b") +
        " CollationKey.compareTo: " +
        key.compareTo(key1));
        } else {
        System.out.println("OK");
        }
            }
        }
        ---------------------------------------------------------

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

              joconnersunw John Oconner (Inactive)
              leosunw Leo Leo (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: