Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LANG-1743 - when ArrayUtils.removeAll meeting 'null' array (PROPOSED CHANGE) #1312

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/main/java/org/apache/commons/lang3/ArrayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5323,7 +5323,7 @@ static Object removeAll(final Object array, final BitSet indices) {
// package protected for access by unit tests
static Object removeAll(final Object array, final int... indices) {
if (array == null) {
return null;
throw new IllegalArgumentException("ArrayUtils.removeAll expected a value but was passed null instead.");
}
final int length = getLength(array);
int diff = 0; // number of distinct indexes, i.e. number of entries that will be removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.commons.lang3;

import static org.apache.commons.lang3.ArrayUtils.removeAll;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
Expand Down Expand Up @@ -552,110 +553,52 @@ public void testRemoveAllLongArrayRemoveNone() {

@Test
public void testRemoveAllNullBooleanArray() {
assertNull(ArrayUtils.removeAll((boolean[]) null, 0));
assertNull(ArrayUtils.removeAll((boolean[]) null, NULL_INDICES));
final boolean[] array0 = {};
assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
final boolean[] array1 = new boolean[1];
assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertThrows(IllegalArgumentException.class, ()-> {removeAll((boolean[]) null,0);});
}

@Test
public void testRemoveAllNullByteArray() {
assertNull(ArrayUtils.removeAll((byte[]) null, 0));
assertNull(ArrayUtils.removeAll((byte[]) null, NULL_INDICES));
final byte[] array0 = {};
assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
final byte[] array1 = new byte[1];
assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertThrows(IllegalArgumentException.class, ()-> {removeAll((byte[]) null,0);});
}

@Test
public void testRemoveAllNullCharArray() {
assertNull(ArrayUtils.removeAll((char[]) null, 0));
assertNull(ArrayUtils.removeAll((char[]) null, NULL_INDICES));
final char[] array0 = {};
assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
final char[] array1 = new char[1];
assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertThrows(IllegalArgumentException.class, ()-> {removeAll((char[]) null,0);});
}

@Test
public void testRemoveAllNullDoubleArray() {
assertNull(ArrayUtils.removeAll((double[]) null, 0));
assertNull(ArrayUtils.removeAll((double[]) null, NULL_INDICES));
final double[] array0 = {};
assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
final double[] array1 = new double[1];
assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertThrows(IllegalArgumentException.class, ()-> {removeAll((double[]) null,0);});
}

@Test
public void testRemoveAllNullFloatArray() {
assertNull(ArrayUtils.removeAll((float[]) null, 0));
assertNull(ArrayUtils.removeAll((float[]) null, NULL_INDICES));
final float[] array0 = {};
assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
final float[] array1 = new float[1];
assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertThrows(IllegalArgumentException.class, ()-> {removeAll((float[]) null,0);});
}

@Test
public void testRemoveAllNullIntArray() {
assertNull(ArrayUtils.removeAll((int[]) null, 0));
assertNull(ArrayUtils.removeAll((int[]) null, NULL_INDICES));
final int[] array0 = {};
assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
final int[] array1 = new int[1];
assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertThrows(IllegalArgumentException.class, ()-> {removeAll((int[]) null,0);});
}

@Test
public void testRemoveAllNullLongArray() {
assertNull(ArrayUtils.removeAll((long[]) null, 0));
assertNull(ArrayUtils.removeAll((long[]) null, NULL_INDICES));
final long[] array0 = {};
assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
final long[] array1 = new long[1];
assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertThrows(IllegalArgumentException.class, ()-> {removeAll((long[]) null,0);});
}

@Test
public void testRemoveAllNullObjectArray() {
assertNull(ArrayUtils.removeAll((Object[]) null, 0));
assertNull(ArrayUtils.removeAll((Object[]) null, NULL_INDICES));
final Object[] array0 = {};
assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
final Object[] array1 = new Object[1];
assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertThrows(IllegalArgumentException.class, ()-> {removeAll((Object[])null,0);});
}

@Test
public void testRemoveAllNullObject(){
assertThrows(IllegalArgumentException.class, ()-> {removeAll((Object)null,0);});
}

@Test
public void testRemoveAllNullShortArray() {
assertNull(ArrayUtils.removeAll((short[]) null, 0));
assertNull(ArrayUtils.removeAll((short[]) null, NULL_INDICES));
final short[] array0 = {};
assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
final short[] array1 = new short[1];
assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
assertThrows(IllegalArgumentException.class, ()-> {removeAll((short[]) null,0);});
}

@Test
Expand Down