You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/03/11 01:16:31 UTC
[lang] [LANG-1385] NumberUtils.createNumber() throws
StringIndexOutOfBoundsException instead of NumberFormatException.
Repository: commons-lang
Updated Branches:
refs/heads/master 9c886bd4a -> 8b62c114c
[LANG-1385] NumberUtils.createNumber() throws
StringIndexOutOfBoundsException instead of NumberFormatException.
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/8b62c114
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/8b62c114
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/8b62c114
Branch: refs/heads/master
Commit: 8b62c114cfc5fd347bd8cb5a391fdfa8cb539435
Parents: 9c886bd
Author: Gary Gregory <ga...@gmail.com>
Authored: Sat Mar 10 18:16:24 2018 -0700
Committer: Gary Gregory <ga...@gmail.com>
Committed: Sat Mar 10 18:16:24 2018 -0700
----------------------------------------------------------------------
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/lang3/math/NumberUtils.java | 2 +-
.../java/org/apache/commons/lang3/math/NumberUtilsTest.java | 5 +++++
3 files changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/8b62c114/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 403bb9d..e20fd2f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -53,6 +53,7 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="LANG-1374" type="fix" dev="kinow" due-to="Jaswanth Bala">Parsing Json Array failed</action>
<action issue="LANG-1371" type="fix" dev="pschumacher" due-to="Dmitry Ovchinnikov">Fix TypeUtils#parameterize to work correctly with narrower-typed array</action>
<action issue="LANG-1370" type="fix" dev="kinow" due-to="Andre Dieb">Fix EventCountCircuitBreaker increment batch</action>
+ <action issue="LANG-1385" type="fix" dev="ggregory" due-to="Rohan Padhye">NumberUtils.createNumber() throws StringIndexOutOfBoundsException instead of NumberFormatException</action>
<action issue="LANG-1367" type="update" dev="ggregory" due-to="Gary Gregory">ObjectUtils.identityToString(Object) and friends should allocate builders and buffers with a size</action>
<action issue="LANG-1352" type="add" dev="pschumacher" due-to="Ruslan Sibgatullin">EnumUtils.getEnumIgnoreCase and isValidEnumIgnoreCase methods added</action>
<action issue="LANG-1372" type="add" dev="pschumacher" due-to="Sérgio Ozaki">Add ToStringSummary annotation</action>
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/8b62c114/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
index 9428ba7..c9cdf6f 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -526,7 +526,7 @@ public class NumberUtils {
case 'L' :
if (dec == null
&& exp == null
- && (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
+ && (numeric.length() > 0 && numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
try {
return createLong(numeric);
} catch (final NumberFormatException nfe) { // NOPMD
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/8b62c114/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
index 7766d88..b0ed8bb 100644
--- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
@@ -1447,6 +1447,11 @@ public class NumberUtilsTest {
compareIsNumberWithCreateNumber("+2.0", true);
}
+ @Test
+ public void testIsNumberLANG1385() {
+ compareIsNumberWithCreateNumber("L", false);
+ }
+
private void compareIsNumberWithCreateNumber(final String val, final boolean expected) {
final boolean isValid = NumberUtils.isCreatable(val);
final boolean canCreate = checkCreateNumber(val);