On Thu, 23 Mar 2023 12:17:55 GMT, Jim Laskey <[email protected]> wrote:
>> src/java.base/share/classes/java/lang/runtime/TemplateRuntime.java line 204:
>>
>>> 202: Object[] values
>>> 203: ) throws Throwable {
>>> 204: List<Object> asList = Collections.unmodifiableList(new
>>> ArrayList<>(Arrays.asList(values)));
>>
>> Suggestion:
>>
>> List<Object> asList = List.of(values);
>>
>> For defensive copy.
>> Don't think processors are harmed by the null-hostile behavior of these
>> list, for many template implementations already use null-hostile lists.
>
> The values list can't be null-hostile for the same reason that string
> concatenation can't be null-hostile. Please point to examples of null-hostile
> lists (other that fragments) being used in the template code. Apologies if I
> misinterpreted your meaning.
There is a trick to do a defensive copy in case the list can contains a null,
you can use `stream.toList()`,
so
List<Object> asList = Arrays.stream(values).toList();
is what you are looking for.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/10889#discussion_r1146455491