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

Hans Aikema commented on COLLECTIONS-701:
-----------------------------------------

[~ggregory]  I retract my remark... I see the test-case was updated and 
updating the current testcase to validate 'adding self twice behaves equal to 
adding self twice for HashSet' shows that both behave equal - yielding a 
stackOverflow, so it matches the described desired behaviour of behaving like a 
HashSet (so I suspect resolving it would (if at all possible) require a fix to 
HashSet).{{{}{}}}

 

{{diff --git 
a/src/test/java/org/apache/commons/collections4/list/Collections701Test.java 
b/src/test/java/org/apache/commons/collections4/list/Collections701Test.java}}
{{index 4f260e393..42c57e88d 100644}}
{{--- 
a/src/test/java/org/apache/commons/collections4/list/Collections701Test.java}}
{{+++ 
b/src/test/java/org/apache/commons/collections4/list/Collections701Test.java}}
{{@@ -44,6 +44,9 @@ public class Collections701Test {}}
{{         set.add(set);}}
{{         assertEquals(1, set.size());}}
{{         assertEquals(set, set.iterator().next());}}
{{+        set.add(set);}}
{{+        assertEquals(1, set.size());}}
{{+        assertEquals(set, set.iterator().next());}}
{{     }}}
{{ }}
{{     @Test}}
{{@@ -53,6 +56,9 @@ public class Collections701Test {}}
{{         list.add(list);}}
{{         assertEquals(1, list.size());}}
{{         assertEquals(list, list.get(0));}}
{{+        list.add(list);}}
{{+        assertEquals(1, list.size());}}
{{+        assertEquals(list, list.get(0));}}

 

yields


{{[ERROR] Errors: }}
{{[ERROR]   Collections701Test.testHashSet » StackOverflow}}
{{[ERROR]   Collections701Test.testSetUniqueList » StackOverflow}}

> StackOverflowError in SetUniqueList.add() 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
>             Fix For: 4.3
>
>
> 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
(v8.20.10#820010)

Reply via email to