commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r981736 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/math/NumberUtils.java test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
Date Tue, 03 Aug 2010 04:41:04 GMT
Author: bayard
Date: Tue Aug  3 04:41:04 2010
New Revision: 981736

URL: http://svn.apache.org/viewvc?rev=981736&view=rev
Log:
Making it so that NumberUtils.createNumber throws a NumberFormatException instead of a StringIndexOutOfBoundsException
when Strings such as 1eE are passed in. Thanks to Ingo Heinrich's report and patch in LANG-638

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java?rev=981736&r1=981735&r2=981736&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
Tue Aug  3 04:41:04 2010
@@ -476,7 +476,7 @@ public class NumberUtils {
         if (decPos > -1) {
 
             if (expPos > -1) {
-                if (expPos < decPos) {
+                if (expPos < decPos || expPos > str.length()) {
                     throw new NumberFormatException(str + " is not a valid number.");
                 }
                 dec = str.substring(decPos + 1, expPos);
@@ -486,6 +486,9 @@ public class NumberUtils {
             mant = str.substring(0, decPos);
         } else {
             if (expPos > -1) {
+                if (expPos > str.length()) {
+                    throw new NumberFormatException(str + " is not a valid number.");
+                }
                 mant = str.substring(0, expPos);
             } else {
                 mant = str;

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java?rev=981736&r1=981735&r2=981736&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
Tue Aug  3 04:41:04 2010
@@ -211,6 +211,9 @@ public class NumberUtilsTest extends Tes
 
         // LANG-521
         assertEquals("createNumber(String) LANG-521 failed", new Float("2."), NumberUtils.createNumber("2."));
+
+        // LANG-638
+        assertFalse("createNumber(String) succeeded", checkCreateNumber("1eE"));
     }
 
     public void testCreateFloat() {



Mime
View raw message