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 b712c8dfd Accept a null delimiter in StringUtils.join(Object[], 
String, int, int)
b712c8dfd is described below

commit b712c8dfd594e5a53d14d0717d5301c6f137e980
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Nov 15 07:46:12 2026 -0500

    Accept a null delimiter in StringUtils.join(Object[], String, int, int)
    
    Follow up to PR #1873.
    
    Clarify StringUtils.join range documentation and extend null-delimiter
    tests
    
    Document IllegalArgumentException for a negative start index on a
    non-null
    array and clarify that the available array entries limit the joined
    count.
    Add null-delimiter coverage for a nonempty partial range and an empty
    array.
---
 src/changes/changes.xml                                     | 1 +
 src/main/java/org/apache/commons/lang3/StringUtils.java     | 7 +++----
 src/test/java/org/apache/commons/lang3/StringUtilsTest.java | 2 ++
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 24c99ddfb..2bf4f24ce 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -51,6 +51,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory, 
gaurav kumar pandey">Fix null parameter-type array handling in MethodUtils and 
ConstructorUtils lookups, including varargs matching and overload 
comparison.</action>
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory, 
Amar Ghugare">[LANG-1425] Clarify DateUtils millisecond parsing 
(#1871).</action>
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory, 
Amar Ghugare">Fix premature overflow in Fraction.divideBy (#1865).</action>
+    <action                   type="fix" dev="ggregory" due-to="Gary Gregory, 
alhuda">Accept a null delimiter in StringUtils.join(Object[], String, int, int) 
(#1873).</action>
     <!-- ADD -->
     <!-- UPDATE -->
   </release>
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java 
b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 7c3e870b4..ca181ac87 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -4713,10 +4713,9 @@ public static String join(final Object[] array, final 
String delimiter) {
      * @param delimiter  The separator character to use, null treated as "".
      * @param startIndex The first index to start joining from.
      * @param endIndex   The index to stop joining from (exclusive).
-     * @return The joined String, {@code null} if null array input; or the 
empty string if {@code endIndex - startIndex <= 0}. The number of joined 
entries is
-     *         given by {@code endIndex - startIndex}.
-     * @throws ArrayIndexOutOfBoundsException Thrown if<br> {@code startIndex 
< 0} or <br> {@code startIndex >= array.length()} or <br> {@code endIndex < 0} 
or
-     *         <br> {@code endIndex > array.length()}.
+     * @return The joined String, {@code null} if null array input; or the 
empty string if {@code endIndex - startIndex <= 0}.
+     *         Otherwise, at most {@code endIndex - startIndex} entries are 
joined, limited by the number of entries remaining in the array.
+     * @throws IllegalArgumentException if the array is non-null and {@code 
startIndex < 0}.
      */
     public static String join(final Object[] array, final String delimiter, 
final int startIndex, final int endIndex) {
         return array != null ? 
Streams.of(array).skip(startIndex).limit(Math.max(0, endIndex - startIndex))
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
index 86a14bb09..fc50f91e9 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
@@ -1180,6 +1180,8 @@ void testJoin_ArrayString_EmptyDelimiter() {
         assertEquals("", StringUtils.join(MIXED_ARRAY_LIST, null, 0, 
MIXED_ARRAY_LIST.length - 1));
         assertEquals(TEXT_LIST_NOSEP, StringUtils.join(ARRAY_LIST, null, 0, 
ARRAY_LIST.length));
         assertEquals("abc", StringUtils.join(new String[] { "a", "b", "c" }, 
null, 0, 3));
+        assertEquals("bc", StringUtils.join(new String[] { "a", "b", "c" }, 
null, 1, 3));
+        assertEquals("", StringUtils.join(EMPTY_ARRAY_LIST, null, 0, 0));
         assertEquals("", StringUtils.join(new String[] { "a", "b", "c" }, 
null, 2, 2));
     }
 

Reply via email to