Skip to content

Commit d9de2fd

Browse files
debbs061yelimkoo
andauthored
[LANG-1810] Deprecate SOFT_MAX_ARRAY_LENGTH in favor of MAX_ARRAY_LENGTH (#1559)
* [LANG-1810] Deprecate SOFT_MAX_ARRAY_LENGTH in favor of MAX_ARRAY_LENGTH * [LANG-1810] Add test coverage for MAX_ARRAY_LENGTH * [LANG-1810] Rename new constant to SAFE_MAX_ARRAY_LENGTH and update Javadoc --------- Co-authored-by: yelimkoo <lydia@tooning.io>
1 parent 0378808 commit d9de2fd

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/main/java/org/apache/commons/lang3/ArrayUtils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,18 @@ public class ArrayUtils {
194194
* The {@code SOFT_MAX_ARRAY_LENGTH} constant from Java's internal ArraySupport class.
195195
*
196196
* @since 3.19.0
197+
* @deprecated This variable will be final in 4.0; to guarantee immutability now, use {@link #SAFE_MAX_ARRAY_LENGTH}.
197198
*/
199+
@Deprecated
198200
public static int SOFT_MAX_ARRAY_LENGTH = Integer.MAX_VALUE - 8;
199201

202+
/**
203+
* The {@code MAX_ARRAY_LENGTH} constant from Java's internal ArraySupport class.
204+
*
205+
* @since 3.21.0
206+
*/
207+
public static final int SAFE_MAX_ARRAY_LENGTH = Integer.MAX_VALUE - 8;
208+
200209
/**
201210
* Copies the given array and adds the given element at the end of the new array.
202211
* <p>

src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6958,4 +6958,9 @@ void testToStringDefault() {
69586958
assertEquals("{<null>}", ArrayUtils.toString(new String[]{null}, "<empty>"));
69596959
assertEquals("{pink,blue}", ArrayUtils.toString(new String[]{"pink", "blue"}, "<empty>"));
69606960
}
6961+
6962+
@Test
6963+
void testMaxArrayLength() {
6964+
assertEquals(Integer.MAX_VALUE - 8, ArrayUtils.SAFE_MAX_ARRAY_LENGTH);
6965+
}
69616966
}

0 commit comments

Comments
 (0)