harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r422922 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Locale.java test/java/tests/api/java/util/LocaleTest.java
Date Tue, 18 Jul 2006 00:01:27 GMT
Author: ndbeyer
Date: Mon Jul 17 17:01:27 2006
New Revision: 422922

URL: http://svn.apache.org/viewvc?rev=422922&view=rev
Log:
Apply patch for HARMONY-901: java.util.Locale(String language, String country, String variant)
constructor doesn't throw NPE when variant is null

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=422922&r1=422921&r2=422922&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
Mon Jul 17 17:01:27 2006
@@ -202,27 +202,35 @@
 	}
 
 	/**
-	 * Constructs a new Locale using the specified language, country, and
-	 * variant codes.
-	 * @param language 
-	 * @param country 
-	 * @param variant 
-	 * 
-	 */
-	public Locale(String language, String country, String variant) {
-		languageCode = language.toLowerCase();
-		// Map new language codes to the obsolete language
-		// codes so the correct resource bundles will be used.
-		if (languageCode.equals("he")) {
+     * Constructs a new Locale using the specified language, country, and
+     * variant codes.
+     * 
+     * @param language
+     * @param country
+     * @param variant
+     * @throws NullPointerException if <code>language</code>,
+     *         <code>country</code> or <code>variant</code> is
+     *         <code>null</code>.
+     */
+    public Locale(String language, String country, String variant) {
+        if (language == null || country == null || variant == null) {
+            throw new NullPointerException();
+        }
+        languageCode = language.toLowerCase();
+        // Map new language codes to the obsolete language
+        // codes so the correct resource bundles will be used.
+        if (languageCode.equals("he")) {
             languageCode = "iw"; //$NON-NLS-1$
         } else if (languageCode.equals("id")) {
             languageCode = "in"; //$NON-NLS-1$
         } else if (languageCode.equals("yi")) {
             languageCode = "ji"; //$NON-NLS-1$
         }
-		countryCode = country.toUpperCase();
-		variantCode = variant;
-	}
+
+        countryCode = country.toUpperCase();
+
+        variantCode = variant;
+    }
 
 	/**
 	 * Answers a new Locale with the same language, country and variant codes as

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=422922&r1=422921&r2=422922&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
Mon Jul 17 17:01:27 2006
@@ -45,6 +45,23 @@
 		Locale x = new Locale("xx", "CV", "ZZ");
 		assertTrue("Failed to create Locale", x.getLanguage().equals("xx")
 				&& (x.getCountry().equals("CV") && x.getVariant().equals("ZZ")));
+                try {
+                   new Locale(null, "CV", "ZZ");
+                   fail("expected NullPointerException with 1st parameter == null");
+                } catch(NullPointerException e) {
+                }
+
+                try {
+                   new Locale("xx", null, "ZZ");
+                   fail("expected NullPointerException with 2nd parameter == null");
+                } catch(NullPointerException e) {
+                }
+
+                try {
+                   new Locale("xx", "CV", null);
+                   fail("expected NullPointerException with 3rd parameter == null");
+                } catch(NullPointerException e) {
+                }
 	}
 
 	/**



Mime
View raw message