Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/org/apache/commons/lang3/ArrayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,18 @@ public class ArrayUtils {
* The {@code SOFT_MAX_ARRAY_LENGTH} constant from Java's internal ArraySupport class.
*
* @since 3.19.0
* @deprecated This variable will be final in 4.0; to guarantee immutability now, use {@link #SAFE_MAX_ARRAY_LENGTH}.
*/
@Deprecated
public static int SOFT_MAX_ARRAY_LENGTH = Integer.MAX_VALUE - 8;

/**
* The {@code MAX_ARRAY_LENGTH} constant from Java's internal ArraySupport class.
*
* @since 3.21.0
*/
public static final int SAFE_MAX_ARRAY_LENGTH = Integer.MAX_VALUE - 8;

/**
* Copies the given array and adds the given element at the end of the new array.
* <p>
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6958,4 +6958,9 @@ void testToStringDefault() {
assertEquals("{<null>}", ArrayUtils.toString(new String[]{null}, "<empty>"));
assertEquals("{pink,blue}", ArrayUtils.toString(new String[]{"pink", "blue"}, "<empty>"));
}

@Test
void testMaxArrayLength() {
assertEquals(Integer.MAX_VALUE - 8, ArrayUtils.SAFE_MAX_ARRAY_LENGTH);
}
}