On Mon, 17 Mar 2025 00:40:46 GMT, Chen Liang <li...@openjdk.org> wrote:
>> src/java.base/share/classes/java/util/ImmutableCollections.java line 798: >> >>> 796: throw new IndexOutOfBoundsException(i); >>> 797: } >>> 798: } >> >> I think `orElseSet` should be outside of the `try` block, otherwise an >> `ArrayIndexOutOfBoundsException` thrown by `mapper.apply` will be wrapped. > > Even better, we should just do a `Preconditions.checkIndex` explicitly. I think the idea here is to avoid having to perform two consecutive range checks—one ahead of access and one as a part of the access. (wrapping of the exception aside). ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r2014504355