RFR: 8266571: Sequenced Collections [v8]
Stuart Marks
smarks at openjdk.org
Thu Apr 20 04:31:05 UTC 2023
On Fri, 24 Mar 2023 22:01:11 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:
>> Stuart Marks has updated the pull request incrementally with four additional commits since the last revision:
>>
>> - Add missing @throws and @since tags.
>> - Convert code samples to snippets.
>> - Various editorial changes.
>> - Fix up toArray(T[]) on reverse-ordered views.
>
> src/java.base/share/classes/java/util/ReverseOrderDequeView.java line 167:
>
>> 165: public <T> T[] toArray(T[] a) {
>> 166: // TODO can probably optimize this
>> 167: return toArray(i -> (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), i));
>
> Hm... Does it follow the spec when the size of `a` is greater than the size of this collection? In this case, we should return the supplied array filling it partially and setting the next element to null. Here, we will always create a new array, which seems to violate the spec.
I've rewritten the `toArray(T[] a)` implementation here and in other places.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/7387#discussion_r1172067817
More information about the core-libs-dev
mailing list