On 23/02/2012 12:22 AM, Alan Bateman wrote:
On 22/02/2012 13:25, Seán Coffey wrote:
Bug recently reported. We enter infinite recursion on a boundary case
for Collections.synchronizedList.remove(..)

Fix is a simple equals check in class method before delegating the call.

bug : http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7144488
webrev : http://cr.openjdk.java.net/~coffeys/webrev.7144488/
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.

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](o) 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.

David

-Alan.

Reply via email to