Applying test/fix from LANG-457 - getting a StringIndexOutOfBounds from createNumber rather than a NumberFormatException
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@711605 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9d8846081a
commit
0d0061f247
|
@ -142,6 +142,9 @@ public final class NumberUtils {
|
|||
if (val.length() == 0) {
|
||||
throw new NumberFormatException("\"\" is not a valid number.");
|
||||
}
|
||||
if (val.length() == 1 && !Character.isDigit(val.charAt(0))) {
|
||||
throw new NumberFormatException(val + " is not a valid number.");
|
||||
}
|
||||
if (val.startsWith("--")) {
|
||||
// this is protection for poorness in java.lang.BigDecimal.
|
||||
// it accepts this as a legal value, but it does not appear
|
||||
|
|
|
@ -520,5 +520,17 @@ public class NumberUtilsTest extends TestCase {
|
|||
fail( "Error calling public no-arg constructor" );
|
||||
}
|
||||
}
|
||||
|
||||
public void testLang457() {
|
||||
String[] badInputs = new String[] { "l", "L", "f", "F", "junk", "bobL"};
|
||||
for(int i=0; i<badInputs.length; i++) {
|
||||
try {
|
||||
NumberUtils.createNumber(badInputs[i]);
|
||||
fail("NumberFormatException was expected for " + badInputs[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
return; // expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue