harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r439959 - 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 Mon, 04 Sep 2006 07:14:45 GMT
Author: pyang
Date: Mon Sep  4 00:14:44 2006
New Revision: 439959

URL: http://svn.apache.org/viewvc?view=rev&rev=439959
Log:
Patch applied for HARMONY-1081 (lasslib][text] 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?view=diff&rev=439959&r1=439958&r2=439959
==============================================================================
--- 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
Mon Sep  4 00:14:44 2006
@@ -191,15 +191,12 @@
 	 */
 	public StringBuffer format(double value, StringBuffer buffer,
 			FieldPosition field) {
-        if(Double.isNaN(value)){
-            return buffer.append(choiceFormats[0]);
-        }
-        for(int i = 0; i < choiceLimits.length; i++) {
-            if (value < choiceLimits[i]) {
-                return buffer.append(choiceFormats[i == 0 ? 0 : i - 1]);
+        for(int i = choiceLimits.length - 1; i >= 0; i--) {
+            if (choiceLimits[i] <= value) {
+                return buffer.append(choiceFormats[i]);
             }
         }
-        return choiceFormats.length == 0 ? buffer : buffer.append(choiceFormats[choiceFormats.length
- 1]);
+        return choiceFormats.length == 0 ? buffer : buffer.append(choiceFormats[0]);
 	}
 
 	/**

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?view=diff&rev=439959&r1=439958&r2=439959
==============================================================================
--- 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
Mon Sep  4 00:14:44 2006
@@ -264,6 +264,7 @@
 		assertEquals("Wrong choice for 3", "Greater than two", r);
 
         // Regression test for HARMONY-1081
+        assertEquals(0, new ChoiceFormat("|").format(Double.NaN, new StringBuffer(), new
FieldPosition(6)).length());
         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