libgcj/10421: java.text.Collator.getInstance returns null for "de" locale

vpuskas@eunet.yu vpuskas@eunet.yu
Wed Apr 16 09:36:00 GMT 2003


>Number:         10421
>Category:       libgcj
>Synopsis:       java.text.Collator.getInstance returns null for "de" locale
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 16 09:36:02 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Vladimir Puskas
>Release:        3.3 20030415 (prerelease)
>Organization:
>Environment:
RedHat 8.0 & Slackware 8.0
>Description:
Collator.getInstance returns null for "de" locale. Sample code throws NullPointerException, 'cause getInstance doesn't create Collator.

Problem is in RuleBasedCollator constructor which doesn't handle '&' reset properly. The fix bellow solves the problem for me.

I don't know if this could be related to PR 9613.
>How-To-Repeat:
/* TestCollator.java */
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.Locale;
class TestCollator {
    public static void main (String[]argv) throws Throwable
    {
        Collator c = Collator.getInstance (new Locale ("de"));
        printCompare (c, "stra\u00dfe", "stra\u00dfe");
        printCompare (c, "M\u00fcnchen", "Muenchen");
        c = new RuleBasedCollator ("<a<b<c&c<d<e");
        printCompare (c, "bc", "bc");
        printCompare (c, "abcde", "abcd");
    }
    public static void printCompare (Collator c, String one, String two)
    {
        System.out.println (one +"-("+ c.compare (one, two) +")-"+ two);
    }
}
/* End of TestCollator.java */
>Fix:
--- gcc-cvs/libjava/java/text/RuleBasedCollator.java    2001-09-07 02:15:47.000000000 +0200
+++ gcc-local/libjava/java/text/RuleBasedCollator.java  2003-03-05 10:41:39.000000000 +0100
@@ -286,12 +286,24 @@
        if (argument.length() == 0)
          throw new ParseException ("invalid character", save);
        String arg = argument.toString();
-       int item_index = vec.indexOf(arg);
+       char arg_c = arg.charAt (0);
+       int item_index = -1;
+       boolean remove2 = false;
+       for (int i = vec.size () - 1; i > 0; --i ) {
+           RBCElement rbc = (RBCElement) vec.elementAt (i);
+           if (arg_c == rbc.key.charAt (0)) {
+               item_index = i;
+               if (arg.equals (rbc.key)&&(c == rbc.relation)) {
+                   remove2 = true;
+               }
+               break;
+           }
+       }
        if (c != '&')
          {
            // If the argument already appears in the vector, then we
            // must remove it in order to re-order.
-           if (item_index != -1)
+           if ((item_index != -1)&&remove2)
              {
                vec.removeElementAt(item_index);
                if (insertion_index >= item_index)
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Java-prs mailing list