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

Collation not working for Simplified Chinese

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.4.2_11"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_11-b06)
      Java HotSpot(TM) Client VM (build 1.4.2_11-b06, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP SP2

      A DESCRIPTION OF THE PROBLEM :
      Using standard Sun provided Collator does not sort Simplified Chinese characters in the proper order. Using Oracle, Microsoft Excel and Java with ICU all produce the correct order. Also some documentation on how collations are implemented for each locale would be helpful.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the source code provided below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      å??a æ??b æ?¦c 大d å??f å??h å? j å?¡k å?¯n å?¦o æ??p
      ACTUAL -
      å??a æ??b æ?¦c 大d å??f å??h å? j å?¡k å?¦o æ??p å?¯n

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      use the following three files.

      --Sort.java--
      import java.text.*;
      import java.util.*;
      public class Sort {
          public static void main(String s[]) {
              Vector list = new Vector();
              list.add(Messages.getString("Sort.0")); //$NON-NLS-1$
              list.add(Messages.getString("Sort.1")); //$NON-NLS-1$
              list.add(Messages.getString("Sort.2")); //$NON-NLS-1$
              list.add(Messages.getString("Sort.3")); //$NON-NLS-1$
              list.add(Messages.getString("Sort.4")); //$NON-NLS-1$
              list.add(Messages.getString("Sort.5")); //$NON-NLS-1$
              list.add(Messages.getString("Sort.6")); //$NON-NLS-1$
              list.add(Messages.getString("Sort.7")); //$NON-NLS-1$
              list.add(Messages.getString("Sort.8")); //$NON-NLS-1$
              list.add(Messages.getString("Sort.9")); //$NON-NLS-1$
              list.add(Messages.getString("Sort.10")); //$NON-NLS-1$
              // Obtain a Chinese collator
              Collator collate = Collator.getInstance(new Locale(Messages.getString("Sort.11"), Messages.getString("Sort.12"))); //$NON-NLS-1$ //$NON-NLS-2$
              Collections.sort(list, collate);
              StringBuffer result = new StringBuffer();
              for (int i = 0; i < list.size(); i++) {
                  result.append(list.elementAt(i));
                  result.append(" "); //$NON-NLS-1$
              }
              System.out.println(result.toString());
          }
      }

      --Messages.java--
      import java.util.MissingResourceException;
      import java.util.ResourceBundle;
      public class Messages {
          private static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$
          private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
          private Messages() {
          }
          public static String getString(String key) {
              try {
                  return RESOURCE_BUNDLE.getString(key);
              } catch (MissingResourceException e) {
                  return '!' + key + '!';
              }
          }
      }

      --messages.properties--
      Sort.0=\u554Aa
      Sort.1=\u628Ab
      Sort.2=\u64E6c
      Sort.3=\u5927d
      Sort.4=\u53D1f
      Sort.5=\u54C8h
      Sort.6=\u51E0j
      Sort.7=\u5361k
      Sort.8=\u55EFn
      Sort.9=\u54E6o
      Sort.10=\u6015p
      Sort.11=zh
      Sort.12=CN
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      use the ICU libraries.

            yhuang Yong Huang (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: