On Thu, 2 Jun 2022 13:59:50 GMT, Сергей Цыпанов <d...@openjdk.java.net> wrote:

>> Claes Redestad has updated the pull request incrementally with one 
>> additional commit since the last revision:
>> 
>>   Review comments, eagerly convert sooner in tryFinally
>
> src/java.base/share/classes/java/lang/invoke/MethodHandles.java line 5462:
> 
>> 5460:         Objects.requireNonNull(target);
>> 5461:         Objects.requireNonNull(newTypes);
>> 5462:         return dropArgumentsToMatch(target, skip, newTypes.toArray(new 
>> Class<?>[0]).clone(), pos, false);
> 
> Do we really need to clone an array returned from `List.toArray()`? As far as 
> I know from the JavaDoc of `List` if the passed array is not long enough to 
> include all the items then the new array must be allocated. Here we always 
> pass empty arrays, so the new ones are returned from `toArray()` method and 
> we don't need `clone()`, right?

The clone is needed - as the `List<Class<?>>` may be a custom implementation of 
List - so you cannot make any assumption on the concrete implementation of 
`toArray`.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8923

Reply via email to