util.concurrent 1.3.4

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

util.concurrent 1.3.4

Elias Ross-5

I know there is an existing bug with

ConcurrentReaderHashMap.keySet().toArray()

but one interesting way I've come across this is with this sort of code:

ConcurrentReaderHashMap cr;
List l = new ArrayList();

  l.addAll(cr.keySet());

What ends up happening is "null" entries end up getting added to the
ArrayList.  This is because, despite what the JavaDoc says:
       
        Appends all of the elements in the specified Collection to the
        end of this list, in the order that they are returned by the
        specified Collection's Iterator.
       
The code for ArrayList calls "toArray" on the set and ignores the
iterator.

    public boolean addAll(Collection<? extends E> c) {
        Object[] a = c.toArray();
        ...
    }


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest