commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <>
Subject [jira] [Commented] (LANG-1261) ArrayUtils.contains returns false
Date Tue, 30 Aug 2016 20:24:21 GMT


ASF GitHub Bot commented on LANG-1261:

Github user coveralls commented on the issue:
    [![Coverage Status](](
    Coverage increased (+0.02%) to 93.477% when pulling **1f56bd103d53c8c6ba7502c6586c26be01bfdb80
on PascalSchumacher:LANG_1261** into **c7c85ee39892df3ca007c6596c41654865be7e43 on apache:master**.

> ArrayUtils.contains returns false
> ---------------------------------
>                 Key: LANG-1261
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.4
>         Environment: Android
>            Reporter: Homer Jay
>              Labels: array, equals
> ArrayUtils.contains(Object[] array, Object objectToFind) wrongly returns false.
> =========================================================
> -Create a superclass "Parent" and override equals and hashcode based on some member id
> -Create a class "Child" extending "Parent". Do not override equals nor hashcode.
> -Let "childrens" be an array of type Child[] containing several instances.
> Create an instance of Parent "p" with the same id as childrens[0], such that childrens[0].equals(p)
returns true and p.equals(childrens[0]) returns true as well.
> Because they are equals, ArrayUtils.contains(childrens, p) should return true. However
it returns false.
> =====================================================
> -Go to ArrayUtils.class, line 1917. In the "indexOf" method implementation, before going
into calling equals for each element of the input array, there is some sort of optimization
check to make sure the instance to be found is an instance of the array type:
> } else if (array.getClass().getComponentType().isInstance(objectToFind)) {
> That line is wrong. In our case, the array contains elements of type "Child", whereas
the object to be found is of type "Parent". They are equals according to the equals implementation
of "Parent", but obviously Children.class.isInstance(p) is false.
> ================================================
> Since the method signature accepts an array of Object[] and an instance of Object, it
should ignore the classes of the arguments. It should be possible to call "ArrayUtils.contains(Child[]
children, Parent p)", in fact it should be possible to do this with any combination of classes,
not only the ones assignable from the class hierarchy.

This message was sent by Atlassian JIRA

View raw message