RFR: 8378580: Make ArrayDeque bulk add methods bootstrap-proof
Eirik Bjørsnøs
eirbjo at openjdk.org
Tue Feb 24 20:44:36 UTC 2026
On Tue, 24 Feb 2026 18:45:29 GMT, Jason Mehrens <duke at openjdk.org> wrote:
> If the given collection 'c' is Collections.synchronziedXXX, then simple loop doesn't lock correctly. ForEach and toArray work correctly with that wrapper class.
The synchronized wrapper collections clearly specify that the user is responsible for synchronizing any iteration or stream operations on those collections. Then, who is the user in this case? The one creating and passing synchronzed collections around, or do we include any collection in the collections framework?
To avoid further headscratching about this, perhaps a good old anonymous class would be less risky?
c.forEach(new Consumer<E>() {
@Override
public void accept(E e) {
addLast(e);
}
});
-------------
PR Comment: https://git.openjdk.org/jdk/pull/29894#issuecomment-3954620028
More information about the core-libs-dev
mailing list