On Wed, 16 Nov 2022 21:19:21 GMT, Tagir F. Valeev <tval...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/template/StringTemplateImplFactory.java >> line 202: >> >>> 200: @SuppressWarnings({"unchecked", "varargs"}) >>> 201: private static <E> List<E> toList(E... elements) { >>> 202: return Collections.unmodifiableList(Arrays.asList(elements)); >> >> Is a defensive copy needed here? >> The caller of `newStringTemplate` could retain a reference to the Object[] >> array and modify it later. > > Alternatively, > `SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArrayNullsAllowed(elements)` > (or `elements.clone()`) could be used here, to reduce amount of wrappers. The `newStringTemplate` methods are internal and elements is safe. Will get rid of the generics and varargs. @amaembo I was using listFromTrustedArrayNullsAllowed early on but ran into an edge case (crash). Will try again. ------------- PR: https://git.openjdk.org/jdk/pull/10889