commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r800988 - in /commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java
Date Tue, 04 Aug 2009 21:32:48 GMT
Author: niallp
Date: Tue Aug  4 21:32:47 2009
New Revision: 800988

URL: http://svn.apache.org/viewvc?rev=800988&view=rev
Log:
BEANUTILS-351 FloatLocaleConverter cannot parse 0 - thanks to Lucian Chirita

Modified:
    commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java
    commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java

Modified: commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java?rev=800988&r1=800987&r2=800988&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java
(original)
+++ commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java
Tue Aug  4 21:32:47 2009
@@ -218,7 +218,7 @@
       final Number parsed = (Number) super.parse(value, pattern);
       double doubleValue = parsed.doubleValue();
       double posDouble = (doubleValue >= (double)0) ? doubleValue : (doubleValue * (double)-1);
-      if (posDouble < Float.MIN_VALUE || posDouble > Float.MAX_VALUE) {
+      if (posDouble != 0 && posDouble < Float.MIN_VALUE || posDouble > Float.MAX_VALUE)
{
           throw new ConversionException("Supplied number is not of type Float: "+parsed);
       }
       return new Float(parsed.floatValue()); // unlike superclass it returns Float type

Modified: commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java?rev=800988&r1=800987&r2=800988&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java
(original)
+++ commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java
Tue Aug  4 21:32:47 2009
@@ -18,7 +18,10 @@
 package org.apache.commons.beanutils.locale.converters;
 
 import java.text.DecimalFormat;
+import java.util.Locale;
+
 import org.apache.commons.beanutils.ConversionException;
+import org.apache.commons.beanutils.locale.LocaleConvertUtils;
 
 /**
  * Test Case for the FloatLocaleConverter class.
@@ -303,6 +306,18 @@
         }
     }
 
+    /**
+     * Test parsing zero - see BEANUTILS-351
+     */
+    public void testParseZero() {
+        try {
+            Object result = LocaleConvertUtils.convert("0", Float.class, Locale.US, null);
+            assertEquals(new Float(0), result);
+        } catch (ConversionException e) {
+            fail("Zero threw ConversionException: " + e);
+        }
+        
+    }
 
 
 }



Mime
View raw message