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

garydgregory 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 d927bfc84 Throw IllegalArgumentException for trailing whitespace in 
(#1701)
d927bfc84 is described below

commit d927bfc848c409af2050d1c32b3e7cf1daed304e
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Jun 11 22:50:06 2026 -0400

    Throw IllegalArgumentException for trailing whitespace in (#1701)
    
    ExtendedMessageFormat argument index.
---
 .../org/apache/commons/lang3/text/ExtendedMessageFormat.java   | 10 +++++-----
 .../apache/commons/lang3/text/ExtendedMessageFormatTest.java   |  6 ++++++
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java 
b/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
index 000e80e8d..ef5c97c7b 100644
--- a/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
+++ b/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
@@ -420,6 +420,9 @@ private int readArgumentIndex(final String pattern, final 
ParsePosition pos) {
             char c = pattern.charAt(pos.getIndex());
             if (Character.isWhitespace(c)) {
                 seekNonWs(pattern, pos);
+                if (pos.getIndex() >= pattern.length()) {
+                    break;
+                }
                 c = pattern.charAt(pos.getIndex());
                 if (c != START_FMT && c != END_FE) {
                     error = true;
@@ -438,12 +441,9 @@ private int readArgumentIndex(final String pattern, final 
ParsePosition pos) {
             result.append(c);
         }
         if (error) {
-            throw new IllegalArgumentException(
-                    "Invalid format argument index at position " + start + ": "
-                            + pattern.substring(start, pos.getIndex()));
+            throw new IllegalArgumentException("Invalid format argument index 
at position " + start + ": " + pattern.substring(start, pos.getIndex()));
         }
-        throw new IllegalArgumentException(
-                "Unterminated format element at position " + start);
+        throw new IllegalArgumentException("Unterminated format element at 
position " + start);
     }
 
     /**
diff --git 
a/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java 
b/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
index 9b74adbc7..f07dde051 100644
--- a/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
@@ -18,6 +18,7 @@
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
 
 import java.text.DateFormat;
 import java.text.FieldPosition;
@@ -288,6 +289,11 @@ public void setUp() {
         registry.put("upper", new UpperCaseFormatFactory());
     }
 
+    @Test
+    void testArgumentIndexTrailingWhitespaceAtEnd() {
+        assertThrowsExactly(IllegalArgumentException.class, () -> new 
ExtendedMessageFormat("{0 ", new HashMap<>()));
+    }
+
     /**
      * Test the built-in choice format.
      */

Reply via email to