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

David Holmes david.holmes at oracle.com
Thu Feb 23 09:56:58 UTC 2012


On 23/02/2012 7:55 PM, Alan Bateman wrote:

On 23/02/2012 02:44, David Holmes wrote:

All of the SynchronizedX.equals methods should be fixed ie SynchronizedSet, SynchronizedList and SynchronizedMap. It should always be valid to ask if a.equals(a). The idiomatic form used elsewhere (CheckedXXX) is: public boolean equals(Object o) { return o == this || list.equals(o); } I'm not a fan of collections containing themselves, but I think it is simple to fix contains(o)/contains[Key]|Value and remove(o) in a similar way. Though none of the wrapped collections currently handle that case, so I'm okay with not addressing this part. I don't see the recursion potential in hashCode() in the wrappers. The hashCode of a Set requires summing the hash codes of each of the elements so it can't work for the case that a set contains itself.

Right, but that's a general problem with collections, not with the wrappers specifically.

Cheers, David

Anyway, I think the best we can do it to have the equals methods use the above form. I wasn't aware of the warning in List that Sean pointed out and maybe there should be similar warnings elsewhere.

-Alan



More information about the core-libs-dev mailing list