On Tue, 2005-01-11 at 16:30, Jeroen Frijters wrote:
> Andrew John Hughes wrote:
> > I'm committing the following patch which fixes the 
> > NullPointerException being thrown.
> 
> You didn't include the patch,

Sorry, I wrote the mail and forgot to actually attach... :(

>  but I have a comment anyway ;-)
> 
> Sun uses a magic currency "XXX" to solve this problem, please at least
> consider taking this approach instead of inventing another scheme. Tests
> for this behavior are already in Mauve.
> 
> Thanks.
> 
> Regards,
> Jeroen

Yes, I've seen this Mauve testcase (which, IIRC, now fails). 
Personally, I feel that copying obscure parts of Sun's implementation is
not right for GNU Classpath.  The above is not documented (AFAICS) in
the specification, and only occurs in Sun's VM.  In fact, the
documentation for setCurrency() suggests that null is a perfectly valid
value for the currency attribute.  I haven't invented a new scheme, but
followed the spec. (and common sense) as much as possible.
getCurrency() returning null is a lot clearer than obscure "XXX" strings
getting into your programs anyway, IMO.  Generally, if you want the
currency symbols, I would imagine you would ensure that they are
available.   

This has already been discussed generally on a recent [email protected]
thread about Mauve, where I believe it was noted that following obscure
parts of Sun's implementation should be considered a buggy test.

Thanks,
-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

No software patents in Europe -- http://nosoftwarepatents.com

"Value your freedom, or you will lose it, teaches history.
`Don't bother us with politics' respond those who don't want to learn."
-- Richard Stallman

"We've all been part of the biggest beta test the world has ever known --
Windows"
-- Victor Wheatman, Gartner
Index: java/text/DecimalFormatSymbols.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/DecimalFormatSymbols.java,v
retrieving revision 1.15
diff -u -3 -p -u -r1.15 DecimalFormatSymbols.java
--- java/text/DecimalFormatSymbols.java	30 Dec 2004 19:37:31 -0000	1.15
+++ java/text/DecimalFormatSymbols.java	11 Jan 2005 15:31:38 -0000
@@ -139,6 +139,10 @@ public final class DecimalFormatSymbols 
   public DecimalFormatSymbols (Locale loc)
   {
     ResourceBundle res;
+
+    currency = null;
+    currencySymbol = "";
+    intlCurrencySymbol = "";
     try
       {
 	res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
@@ -148,7 +152,20 @@ public final class DecimalFormatSymbols 
       {
 	res = null;
       }
-    setCurrency(Currency.getInstance(loc));
+    try
+      {
+	Currency localeCurrency;
+
+	localeCurrency = Currency.getInstance(loc);
+	if (localeCurrency != null)
+	  {
+	    setCurrency(localeCurrency);
+	  }
+      }
+    catch(IllegalArgumentException exception)
+      {
+	/* Locale has an invalid currency */
+      }
     decimalSeparator = safeGetChar (res, "decimalSeparator", '.');
     digit = safeGetChar (res, "digit", '#');
     exponential = safeGetChar (res, "exponential", 'E');
@@ -393,9 +410,9 @@ public final class DecimalFormatSymbols 
    */
   public void setCurrency (Currency currency)
   {
-    this.currency = currency;
     intlCurrencySymbol = currency.getCurrencyCode();
     currencySymbol = currency.getSymbol();
+    this.currency = currency;
   }
 
   /**
Index: java/util/Currency.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Currency.java,v
retrieving revision 1.9
diff -u -3 -p -u -r1.9 Currency.java
--- java/util/Currency.java	11 Jan 2005 09:44:32 -0000	1.9
+++ java/util/Currency.java	11 Jan 2005 15:31:39 -0000
@@ -168,7 +168,8 @@ public final class Currency 
     /* If there is no country code, return */
     if (countryCode.equals(""))
       {
-        return;
+        throw new
+	  IllegalArgumentException("The specified country code is invalid");
       }
     /* Construct the key for the currency */
     currencyKey = countryCode + ".currency";
@@ -248,6 +249,11 @@ public final class Currency 
      */
     Currency newCurrency;
 
+    if (locale == null || locale.getCountry() == null)
+      {
+	throw new
+	  NullPointerException("The locale or its country is null.");
+      }
     /* Attempt to get the currency from the cache */
     newCurrency = (Currency) cache.get(locale);
     if (newCurrency == null)
@@ -299,7 +305,6 @@ public final class Currency 
     for (int i = 0;i < allLocales.length; i++)
       {
 	Currency testCurrency = getInstance (allLocales[i]);
-	
 	if (testCurrency != null &&
 	    testCurrency.getCurrencyCode().equals(currencyCode))
 	  return testCurrency;

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Classpath mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath

Reply via email to