commons-issues mailing list archives

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

    [ https://issues.apache.org/jira/browse/LANG-1261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15450049#comment-15450049
] 

ASF GitHub Bot commented on LANG-1261:
--------------------------------------

Github user coveralls commented on the issue:

    https://github.com/apache/commons-lang/pull/183
  
    
    [![Coverage Status](https://coveralls.io/builds/7676541/badge)](https://coveralls.io/builds/7676541)
    
    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: https://issues.apache.org/jira/browse/LANG-1261
>             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.
> STEPS TO REPRODUCE
> =========================================================
> -Create a superclass "Parent" and override equals and hashcode based on some member id
variable.
> -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.
> WHERE THE BUG IS LOCATED
> =====================================================
> -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.
> EXPECTED BEHAVIOR
> ================================================
> 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
(v6.3.4#6332)

Mime
View raw message