harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r429685 - in /incubator/harmony/enhanced/classlib/trunk/modules/text/src: main/java/java/text/ChoiceFormat.java test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java
Date Tue, 08 Aug 2006 15:18:27 GMT
Author: pyang
Date: Tue Aug  8 08:18:27 2006
New Revision: 429685

URL: http://svn.apache.org/viewvc?rev=429685&view=rev
Log:
Fix for HARMONY-1081 ([classlib][lang] ChoiceFormat.format(double, StringBuffer, FieldPosition)
throws unexpected ArrayIndexOutOfBoundsException)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java?rev=429685&r1=429684&r2=429685&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java
Tue Aug  8 08:18:27 2006
@@ -191,16 +191,15 @@
 	 */
 	public StringBuffer format(double value, StringBuffer buffer,
 			FieldPosition field) {
-		if (Double.isNaN(value)
-				|| (choiceLimits.length > 1 && value < choiceLimits[1])) {
+        if(Double.isNaN(value)){
             return buffer.append(choiceFormats[0]);
         }
-		for (int i = 2; i < choiceLimits.length; i++) {
-            if (value >= choiceLimits[i - 1] && value < choiceLimits[i]) {
-                return buffer.append(choiceFormats[i - 1]);
+        for(int i = 0; i < choiceLimits.length; i++) {
+            if (value < choiceLimits[i]) {
+                return buffer.append(choiceFormats[i == 0 ? 0 : i - 1]);
             }
         }
-		return buffer.append(choiceFormats[choiceFormats.length - 1]);
+        return choiceFormats.length == 0 ? buffer : buffer.append(choiceFormats[choiceFormats.length
- 1]);
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java?rev=429685&r1=429684&r2=429685&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java
Tue Aug  8 08:18:27 2006
@@ -262,6 +262,10 @@
         buf.setLength(0);
         r = f1.format(3, buf, field).toString();
 		assertEquals("Wrong choice for 3", "Greater than two", r);
+
+        // Regression test for HARMONY-1081
+        assertEquals(0, new ChoiceFormat("|").format(1, new StringBuffer(), new FieldPosition(6)).length());
+        assertEquals("Less than one", f1.format(Double.NaN, new StringBuffer(), field).toString());
     }
 
     /**



Mime
View raw message