RFR: 8301220: Return value of toArray() of Сollection types from java.base should be trusted
Sergey Tsypanov
stsypanov at openjdk.org
Fri Jan 27 09:45:02 UTC 2023
On Thu, 26 Jan 2023 06:46:16 GMT, Glavo <duke at openjdk.org> wrote:
> I checked the `java.base` module, and all the `Collection#toArray()` method of collections be implemented correctly.
>
> Their return values can be trusted, so many unnecessary array duplication can be eliminated.
You could also have a look into `PriorityQueue.initElementsFromCollection()`
@Glavo I've filed https://bugs.openjdk.org/browse/JDK-8301220 so you can use it for this PR.
src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java line 746:
> 744: int len = es.length;
> 745: Object[] newElements;
> 746: if (len == 0 && c.getClass().getModule() == Object.class.getModule()) {
I think as soon as we anyway assign the array from trusted collection, we don't need `len == 0` check here any more
-------------
PR: https://git.openjdk.org/jdk/pull/12212
More information about the core-libs-dev
mailing list