This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 6f2c93cee LANG-1721: Fix wrong number check that cause 
StringIndexOutOfBoundsException (#1140)
6f2c93cee is described below

commit 6f2c93ceeecc48f4eca2c52345a7bf33329211c1
Author: Arthur Chan <[email protected]>
AuthorDate: Wed Dec 6 14:44:40 2023 +0000

    LANG-1721: Fix wrong number check that cause 
StringIndexOutOfBoundsException (#1140)
    
    * LANG-1721: Fix wrong number check that cause 
StringIndexOutOfBoundsException
    
    Signed-off-by: Arthur Chan <[email protected]>
    
    * LANG-1721: Fix unit test
    
    Signed-off-by: Arthur Chan <[email protected]>
    
    ---------
    
    Signed-off-by: Arthur Chan <[email protected]>
---
 src/main/java/org/apache/commons/lang3/math/NumberUtils.java     | 2 +-
 src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

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 11da21db3..03e1b938a 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -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);
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 3e53e1a97..d2a98ab83 100644
--- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
@@ -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"));
+    }
 }

Reply via email to