LANG-1721: Fix wrong number check that cause StringIndexOutOfBoundsException (#1140)
* LANG-1721: Fix wrong number check that cause StringIndexOutOfBoundsException Signed-off-by: Arthur Chan <arthur.chan@adalogics.com> * LANG-1721: Fix unit test Signed-off-by: Arthur Chan <arthur.chan@adalogics.com> --------- Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
This commit is contained in:
parent
d7e927deff
commit
6f2c93ceee
|
@ -361,7 +361,7 @@ public class NumberUtils {
|
|||
final boolean requestType = !Character.isDigit(lastChar) && lastChar != '.';
|
||||
if (decPos > -1) { // there is a decimal point
|
||||
if (expPos > -1) { // there is an exponent
|
||||
if (expPos < decPos || expPos > length) { // prevents double exponent causing IOOBE
|
||||
if (expPos <= decPos || expPos > length) { // prevents double exponent causing IOOBE
|
||||
throw new NumberFormatException(str + " is not a valid number.");
|
||||
}
|
||||
dec = str.substring(decPos + 1, expPos);
|
||||
|
|
|
@ -1743,4 +1743,9 @@ public class NumberUtilsTest extends AbstractLangTest {
|
|||
assertEquals(12345, NumberUtils.toShort("12345", (short) 5), "toShort(String, short) 1 failed");
|
||||
assertEquals(5, NumberUtils.toShort("1234.5", (short) 5), "toShort(String, short) 2 failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidNumber() {
|
||||
assertThrows(NumberFormatException.class, () -> NumberUtils.createNumber("E123e.3"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue