Re: Vector (was Re: Change character in string)
On Sat, 14 Mar 2009, Bent C Dalager wrote:
The same listIterator is used by SynchronizedArrayList but the get()
/it/ calls is that of the base unscynchronized ArrayList.
Either way of doing it is wrong: in one case you end up deadlocking and
in the other you're not synchronizing on all the data that you need. And
neither of these flaws is obvious to the user, or even documented in any
way that I know of.
I have always found this rather serious because, of all the methods you
can call on a List you'd expect equals() to be among the safer ones. All
sorts of algorithms rely on being able to use it all the time - but
perhaps that's my GUI bias shining through.
I can't vouch for my own unbiasedness, but this definitely looks like a
bug to me. I think you can just about defend the status quo on the grounds
of the wording of synchronizedList's documentation:
Returns a synchronized (thread-safe) list backed by the specified list.
Which says that the returned list is thread-safe (whatever that means),
but nothing about it interacting with other lists in a thread-safe way.
But still, it's lame.
Even with better locking in the synchronizedList wrapper, though, you
can't guarantee thread-safety - if the other list is a normal
non-synchronized one, there's no way to detect or prevent modification by
another thread during the comparison. Still, it would be good to have a
promise that if access to the other list *is* properly synchronized, then
equals() *will* be thread-safe.
tom
--
Everyone in the world is doing something without me.