<i18n dev> RFR: JDK-8285932 Implementation of JEP 430 String Templates (Preview) [v46]
Rémi Forax
forax at openjdk.org
Thu Mar 23 16:39:44 UTC 2023
On Thu, 23 Mar 2023 12:17:55 GMT, Jim Laskey <jlaskey at openjdk.org> 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
More information about the i18n-dev
mailing list