RFD: ArrayDeque bulk adds and lambda
Eirik Bjørsnøs
eirbjo at gmail.com
Sat Feb 21 10:08:57 UTC 2026
Hi,
While working on JDK-8375580, I noticed the following code and comment in
URLClassPath:
// can't use ArrayDeque#addAll or new ArrayDeque(Collection);
// it's too early in the bootstrap to trigger use of lambdas
[..]
for (int i = 0; i < size; i++)
unopenedUrls.add(path.get(i));
This code avoids using bulk add operations on ArrayDeque, presumably to
work around problems caused by early initialization of lambda machinery.
And indeed, in ArrayDeque::copyElements, we find this:
c.forEach(this::addLast);
While I don't know if the above code is still a concern, should we consider
replacing it with a simple for loop, like this:
for (E e : c) {
addLast(e);
}
Can this make ArrayDeque somewhat safer to use in early bootstrap code?
Wdyt?
Eirik.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20260221/ccf273e9/attachment-0001.htm>
More information about the core-libs-dev
mailing list