Repository: commons-lang
Updated Branches:
  refs/heads/master 72bbbbc55 -> 42f2058c8


LANG-1261: ArrayUtils#contains and ArrayUtils#indexOf should compare objects 
with different types


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/1f56bd10
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/1f56bd10
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/1f56bd10

Branch: refs/heads/master
Commit: 1f56bd103d53c8c6ba7502c6586c26be01bfdb80
Parents: f30c460
Author: pascalschumacher <pascalschumac...@gmx.net>
Authored: Tue Aug 23 19:22:55 2016 +0200
Committer: pascalschumacher <pascalschumac...@gmx.net>
Committed: Tue Aug 30 22:00:37 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/commons/lang3/ArrayUtils.java |  2 +-
 .../org/apache/commons/lang3/ArrayUtilsTest.java  | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/1f56bd10/src/main/java/org/apache/commons/lang3/ArrayUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java 
b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
index 1d33fcf..b2f019e 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;

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/1f56bd10/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
index a50ed1a..2d137c8 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() {

Reply via email to