Fixing LANG-300 (reported by Jeremy Lemaire) - 1L to 9L incorrectly throw exceptions when passed into NumberUtils.createNumber. Fixed in both the math.NumbersUtils and the deprecated NumberUtils classes.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@488819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2006-12-19 21:50:04 +00:00
parent 868dd28444
commit 1536077409
3 changed files with 8 additions and 4 deletions

View File

@ -192,8 +192,7 @@ public final class NumberUtils {
case 'L' :
if (dec == null
&& exp == null
&& isDigits(numeric.substring(1))
&& (numeric.charAt(0) == '-' || Character.isDigit(numeric.charAt(0)))) {
&& (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
try {
return createLong(numeric);
} catch (NumberFormatException nfe) {

View File

@ -451,8 +451,7 @@ public class NumberUtils {
case 'L' :
if (dec == null
&& exp == null
&& isDigits(numeric.substring(1))
&& (numeric.charAt(0) == '-' || Character.isDigit(numeric.charAt(0)))) {
&& (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
try {
return createLong(numeric);
} catch (NumberFormatException nfe) {

View File

@ -1364,5 +1364,11 @@ public class NumberUtilsTest extends TestCase {
assertTrue(NumberUtils.FLOAT_ONE.floatValue() == 1.0f);
assertTrue(NumberUtils.FLOAT_MINUS_ONE.floatValue() == -1.0f);
}
public void testLang300() {
NumberUtils.createNumber("-1l");
NumberUtils.createNumber("01l");
NumberUtils.createNumber("1l");
}
}