You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2006/08/02 07:59:46 UTC

svn commit: r427906 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Locale.java test/java/tests/api/java/util/LocaleTest.java

Author: pyang
Date: Tue Aug  1 22:59:45 2006
New Revision: 427906

URL: http://svn.apache.org/viewvc?rev=427906&view=rev
Log:
Fix for HARMONY-1027 ([classlib][luni] java.util.Locale.toString() returns wrong value)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Locale.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Locale.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Locale.java?rev=427906&r1=427905&r2=427906&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Locale.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Locale.java Tue Aug  1 22:59:45 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -219,11 +219,11 @@
         languageCode = language.toLowerCase();
         // Map new language codes to the obsolete language
         // codes so the correct resource bundles will be used.
-        if (languageCode.equals("he")) {
+        if (languageCode.equals("he")) {//$NON-NLS-1$
             languageCode = "iw"; //$NON-NLS-1$
-        } else if (languageCode.equals("id")) {
+        } else if (languageCode.equals("id")) {//$NON-NLS-1$
             languageCode = "in"; //$NON-NLS-1$
-        } else if (languageCode.equals("yi")) {
+        } else if (languageCode.equals("yi")) {//$NON-NLS-1$
             languageCode = "ji"; //$NON-NLS-1$
         }
 
@@ -307,6 +307,7 @@
                             }
 						}
 					} catch (IOException e) {
+                        //Empty
 					}
 				} else {
 					// Handle ZIP/JAR files.
@@ -317,12 +318,13 @@
                             ZipEntry e = entries.nextElement();
 							String name = e.getName();
 							if (name.startsWith(prefix)
-									&& name.endsWith(".class")) {
+									&& name.endsWith(".class")) {//$NON-NLS-1$
                                 result.add(name);
                             }
 						}
 						zip.close();
 					} catch (IOException e) {
+                       // Empty
 					}
 				}
 			}
@@ -612,6 +614,7 @@
 			bundle.getString("CS"); //$NON-NLS-1$
 			hasCS = true;
 		} catch (MissingResourceException e) {
+            //Empty
 		}
 
 		Enumeration<String> keys = bundle.getKeys(); // to initialize the table
@@ -623,7 +626,7 @@
 		int index = 0;
 		while (keys.hasMoreElements()) {
 			String element = keys.nextElement();
-			if (!element.equals("CS")) {
+			if (!element.equals("CS")) {//$NON-NLS-1$
                 result[index++] = element;
             }
 		}
@@ -706,14 +709,14 @@
 	 * @return the string representation of this Locale
 	 */
 	public final String toString() {
-		StringBuffer result = new StringBuffer();
+		StringBuilder result = new StringBuilder();
 		result.append(languageCode);
 		if (countryCode.length() > 0) {
 			result.append('_');
 			result.append(countryCode);
 		}
-		if (variantCode.length() > 0) {
-			if (countryCode.length() == 0) {
+		if (variantCode.length() > 0 && result.length() > 0 ) {
+			if (0 == countryCode.length()) {
                 result.append("__"); //$NON-NLS-1$
             } else {
                 result.append('_');

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java?rev=427906&r1=427905&r2=427906&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java Tue Aug  1 22:59:45 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -320,6 +320,10 @@
 		assertEquals("Wrong representation 6", "en_CA", l.toString());
 		l = new Locale("en", "CA", "VAR");
 		assertEquals("Wrong representation 7", "en_CA_VAR", l.toString());
+        
+        l = new Locale("", "", "var");
+        assertEquals("Wrong representation 8", "", l.toString());
+
 	}
 
 	/**