[jira] [Commented] (COLLECTIONS-701) SetUniqueList.add() crashes due to infinite recursion when it receives itself

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (COLLECTIONS-701) SetUniqueList.add() crashes due to infinite recursion when it receives itself

JIRA jira@apache.org

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

ASF GitHub Bot commented on COLLECTIONS-701:
--------------------------------------------

Github user garydgregory commented on the issue:

    https://github.com/apache/commons-collections/pull/57
 
    Hi @drajakumar ,
   
    I'm not sure this patch makes sense. Take a look at ```org.apache.commons.collections4.list.Collections701Test```: For ```ArrayList``` and ```HashSet```, adding a collection to itself is fine.
   
    In this patch, the argument is not only silently ignored, but the behavior is not even documented. Whatever we do, we really need to document _anything_ that deviates from the standard JRE ```List``` contract.
   
    IMO, the fix should be so that a ```SetUniqueList``` behaves like a ```ArrayList``` and ```HashSet```, it just works.


> SetUniqueList.add() crashes due to infinite recursion when it receives itself
> -----------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-701
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-701
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Collection
>    Affects Versions: 3.2.2
>            Reporter: Shin Hong
>            Priority: Critical
>
> Hi.
> We found that the following test case fails with a StackOverFlowError exception:
> {code:java}
> test() {       
>    SetUniqueList l = new SetUniqueList(new LinkedList<Object>()) ;       
>    l.add((Object) l) ;   
> }{code}
> The add() execution traps into an infinite recursion which crashes the program.
> From the stack trace, we found that the infinite recursion occurs
> at AbstractList.hashCode() since it invokes hashCode() of each of its elements.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)