RFR : 7144488 StackOverflowError occurres on list via Collections.synchronizedList(List)

Seán Coffey sean.coffey at oracle.com
Wed Feb 22 14:43:02 UTC 2012

Yes, I stumbled across another few issues in the Collections class while 
looking to expand the testcase for this one. Below are other such cases.

Various hashCode methods lead to recursive calls and this has been 
discussed in the past. It's also mentioned in the javadocs (albeit 
somewhat vaguely)

> Note: While it is permissible for lists to contain themselves as
> elements, extreme caution is advised: the equals and hashCode methods
> are no longer well defined on a such a list.

Due to the known issue, I wasn't planning on making any further changes.


         List list = Collections.synchronizedList(new ArrayList());
         //int i = list.hashCode(); // recursive call
         //list.remove(list); // recursive call (FIXED with 7144488)

         /* Sets also suffer similar problems */
         Set s = Collections.synchronizedSet(new HashSet());
         //s.remove(s); // recursive call

On 22/02/12 14:22, Alan Bateman wrote:
> Sean - the fix looks okay to me but I assume there are other cases, 
> like with SynchronizedSet and hashCode for example. I don't know if 
> they are all fixable, at least not the hashCode cases.
> -Alan.

More information about the core-libs-dev mailing list