diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 1d33fcf13..b2f019eda 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -3184,7 +3184,7 @@ public class ArrayUtils { return i; } } - } else if (array.getClass().getComponentType().isInstance(objectToFind)) { + } else { for (int i = startIndex; i < array.length; i++) { if (objectToFind.equals(array[i])) { return i; diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java index a50ed1ab2..2d137c822 100644 --- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java @@ -2953,7 +2953,23 @@ public class ArrayUtilsTest { assertTrue(ArrayUtils.contains(array, null)); 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 public void testIndexOfLong() {