commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1056853 - in /commons/proper/lang/branches/LANG_2_X/src: main/java/org/apache/commons/lang/math/NumberUtils.java test/java/org/apache/commons/lang/math/NumberUtilsTest.java
Date Sun, 09 Jan 2011 01:07:04 GMT
Author: niallp
Date: Sun Jan  9 01:07:04 2011
New Revision: 1056853

URL: http://svn.apache.org/viewvc?rev=1056853&view=rev
Log:
Port LANG-638 to LANG 2.x Branch - NumberUtils createNumber() throws a StringIndexOutOfBoundsException
when argument containing "e" and "E" is passed in

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

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/math/NumberUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/math/NumberUtils.java?rev=1056853&r1=1056852&r2=1056853&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/math/NumberUtils.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/math/NumberUtils.java
Sun Jan  9 01:07:04 2011
@@ -520,7 +520,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);
@@ -530,6 +530,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/branches/LANG_2_X/src/test/java/org/apache/commons/lang/math/NumberUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/math/NumberUtilsTest.java?rev=1056853&r1=1056852&r2=1056853&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/math/NumberUtilsTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/math/NumberUtilsTest.java
Sun Jan  9 01:07:04 2011
@@ -229,6 +229,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