You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2016/04/24 05:37:36 UTC

[lang] LANG-1205: NumberUtils.createNumber() behaves inconsistently with NumberUtils.isNumber() This closes github #87 thanks to pbrose

Repository: commons-lang
Updated Branches:
  refs/heads/master 5e62bf80f -> b877fb9ab


LANG-1205: NumberUtils.createNumber() behaves inconsistently with NumberUtils.isNumber()
This closes github #87 thanks to pbrose


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/b877fb9a
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/b877fb9a
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/b877fb9a

Branch: refs/heads/master
Commit: b877fb9abef4a19eec9cc7329acbd433648b8f7b
Parents: 5e62bf8
Author: Chas Honton <ch...@apache.org>
Authored: Sat Apr 23 20:33:50 2016 -0700
Committer: Chas Honton <ch...@apache.org>
Committed: Sat Apr 23 20:35:15 2016 -0700

----------------------------------------------------------------------
 src/changes/changes.xml                         |  1 +
 .../apache/commons/lang3/math/NumberUtils.java  |  4 ++--
 .../commons/lang3/math/NumberUtilsTest.java     | 24 ++++++++++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/b877fb9a/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f18253d..a4d815b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.5" date="tba" description="tba">
+    <action issue="LANG-1205" type="fix" dev="chas" due-to="pbrose">NumberUtils.createNumber() behaves inconsistently with NumberUtils.isNumber()</action>
     <action issue="LANG-1115" type="add" dev="chas" due-to="Jim Lloyd, Joe Ferner">Add support for varargs in ConstructorUtils, MemberUtils, and MethodUtils</action>
     <action issue="LANG-1134" type="add" dev="chas" due-to="Alan Smithee">New methods for lang3.Validate</action>
     <action issue="LANG-1222" type="fix" dev="ggregory" due-to="Adam J.">Fix for incorrect comment on StringUtils.containsIgnoreCase method</action>

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/b877fb9a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
index b53ba98..c640ceb 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -542,7 +542,7 @@ public class NumberUtils {
                 case 'f' :
                 case 'F' :
                     try {
-                        final Float f = NumberUtils.createFloat(numeric);
+                        final Float f = NumberUtils.createFloat(str);
                         if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
                             //If it's too big for a float or the float value = 0 and the string
                             //has non-zeros in it, then float does not have the precision we want
@@ -556,7 +556,7 @@ public class NumberUtils {
                 case 'd' :
                 case 'D' :
                     try {
-                        final Double d = NumberUtils.createDouble(numeric);
+                        final Double d = NumberUtils.createDouble(str);
                         if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
                             return d;
                         }

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/b877fb9a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
index bfa1949..92977d5 100644
--- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
@@ -318,6 +318,30 @@ public class NumberUtilsTest {
         NumberUtils.createNumber("1eE+00001");
     }
 
+    @Test(expected=NumberFormatException.class)
+    // Check that the code fails to create a valid number when there are multiple trailing 'f' characters (LANG-1205)
+    public void testCreateNumberFailure_5() {
+        NumberUtils.createNumber("1234.5ff");
+    }
+
+    @Test(expected=NumberFormatException.class)
+    // Check that the code fails to create a valid number when there are multiple trailing 'F' characters (LANG-1205)
+    public void testCreateNumberFailure_6() {
+        NumberUtils.createNumber("1234.5FF");
+    }
+
+    @Test(expected=NumberFormatException.class)
+    // Check that the code fails to create a valid number when there are multiple trailing 'd' characters (LANG-1205)
+    public void testCreateNumberFailure_7() {
+        NumberUtils.createNumber("1234.5dd");
+    }
+
+    @Test(expected=NumberFormatException.class)
+    // Check that the code fails to create a valid number when there are multiple trailing 'D' characters (LANG-1205)
+    public void testCreateNumberFailure_8() {
+        NumberUtils.createNumber("1234.5DD");
+    }
+
     // Tests to show when magnitude causes switch to next Number type
     // Will probably need to be adjusted if code is changed to check precision (LANG-693)
     @Test