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

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@981736 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2010-08-03 04:41:04 +00:00
parent bbcba273ad
commit 50c1fdecb4
2 changed files with 7 additions and 1 deletions

View File

@ -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;

View File

@ -211,6 +211,9 @@ public class NumberUtilsTest extends TestCase {
// 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() {