Patch: FYI: DecimalFormat fixlet

Tom Tromey tromey@redhat.com
Mon Aug 4 22:04:00 GMT 2003


I'm checking this in on the trunk.

This fixes a DecimalFormat bug noticed by a Classpath developer.
There's a new Mauve test for this.

Tom

Index: ChangeLog
from  David P Grove  <groved@us.ibm.com>

	* java/text/DecimalFormat.java (format): avoid ArithmeticException
	when groupingSize is 0.
	(parse): Likewise.

Index: java/text/DecimalFormat.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/DecimalFormat.java,v
retrieving revision 1.7
diff -u -r1.7 DecimalFormat.java
--- java/text/DecimalFormat.java 9 Jun 2003 16:20:14 -0000 1.7
+++ java/text/DecimalFormat.java 4 Aug 2003 20:31:23 -0000
@@ -474,7 +474,7 @@
 	    intPart = Math.floor(intPart / 10);
 
 	    // Append group separator if required.
-	    if (groupingUsed && count > 0 && count % groupingSize == 0)
+	    if (groupingUsed && count > 0 && groupingSize != 0 && count % groupingSize == 0)
 	      dest.insert(index, symbols.getGroupingSeparator());
 
 	    dest.insert(index, (char) (symbols.getZeroDigit() + dig));
@@ -602,7 +602,7 @@
 	  }
 
 	// Append group separator if required.
-	if (groupingUsed && count > 0 && count % groupingSize == 0)
+	if (groupingUsed && count > 0 && groupingSize != 0 && count % groupingSize == 0)
 	  dest.insert(index, symbols.getGroupingSeparator());
 
 	dest.insert(index, (char) (symbols.getZeroDigit() + dig));
@@ -748,7 +748,8 @@
 	// FIXME: what about grouping size?
 	if (groupingUsed && c == symbols.getGroupingSeparator())
 	  {
-	    if (last_group != -1
+	    if (last_group != -1 
+		&& groupingSize != 0  
 		&& (index - last_group) % groupingSize != 0)
 	      {
 		pos.setErrorIndex(index);
@@ -765,7 +766,8 @@
 	  break;
 	else if (c == symbols.getDecimalSeparator())
 	  {
-	    if (last_group != -1
+	    if (last_group != -1 
+		&& groupingSize != 0 
 		&& (index - last_group) % groupingSize != 0)
 	      {
 		pos.setErrorIndex(index);



More information about the Java-patches mailing list