LANG-1261: ArrayUtils#contains and ArrayUtils#indexOf should compare objects with different types
This commit is contained in:
parent
f30c4607a2
commit
1f56bd103d
|
@ -3184,7 +3184,7 @@ public class ArrayUtils {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (array.getClass().getComponentType().isInstance(objectToFind)) {
|
} else {
|
||||||
for (int i = startIndex; i < array.length; i++) {
|
for (int i = startIndex; i < array.length; i++) {
|
||||||
if (objectToFind.equals(array[i])) {
|
if (objectToFind.equals(array[i])) {
|
||||||
return i;
|
return i;
|
||||||
|
|
|
@ -2953,7 +2953,23 @@ public class ArrayUtilsTest {
|
||||||
assertTrue(ArrayUtils.contains(array, null));
|
assertTrue(ArrayUtils.contains(array, null));
|
||||||
assertFalse(ArrayUtils.contains(array, "notInArray"));
|
assertFalse(ArrayUtils.contains(array, "notInArray"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContains_LANG_1261() {
|
||||||
|
class LANG1261ParentObject {
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class LANG1261ChildObject extends LANG1261ParentObject {
|
||||||
|
}
|
||||||
|
|
||||||
|
Object[] array = new LANG1261ChildObject[] { new LANG1261ChildObject() };
|
||||||
|
|
||||||
|
assertTrue(ArrayUtils.contains(array, new LANG1261ParentObject()));
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@Test
|
@Test
|
||||||
public void testIndexOfLong() {
|
public void testIndexOfLong() {
|
||||||
|
|
Loading…
Reference in New Issue