On Tue, 11 Aug 2026 18:43:29 GMT, Chen Liang <[email protected]> wrote:

>> same here
>
> If that's the case, I would recommend `JsonArray.of` to simply become:
> 
>         return new JsonArrayImpl(List.copyOf(src));
> 
> Where `List.copyOf` null checks the list itself and every single element in 
> the list.

Also, `List.copyOf(…)` should probably be optimised to call 
`ImmutableCollections​::listFromTrustedArray` when the list’s class is exactly 
`java.util.ArrayList.class`, similar to what `Collectors​.toImmutableList()` 
does[^1][^2]:
https://github.com/openjdk/jdk/blob/34dda4ecd89e07d4530f9c26e88f9968788d695f/src/java.base/share/classes/java/util/stream/Collectors.java#L261-L269

[^1]: Which would make it possible to change its implementation to just use 
`List::copyOf` for the finisher.
[^2]: The finisher of which I’ve used in some of my code as a way to convert 
`ArrayList`s directly to immutable lists without going through an intermediate 
`Object[]`.

[JDK‑8156071]: https://bugs.openjdk.org/browse/JDK-8156071

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

PR Review Comment: https://git.openjdk.org/jdk/pull/32282#discussion_r3774849249

Reply via email to