8372688: Test out-of-bounds indexing for List.ofLazy()::get

Reviewed-by: jvernee
This commit is contained in:
Per Minborg 2026-04-21 12:50:25 +00:00
parent e3e7ecd1b2
commit 53d0e4c370

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -153,6 +153,15 @@ final class LazyListTest {
assertEquals(-1, lazy.lastIndexOf(SIZE + 1));
}
@ParameterizedTest
@MethodSource("lazyLists")
void bounds(List list) {
IntStream.range(0, list.size())
.forEach(i -> assertEquals(IDENTITY.apply(i), list.get(i)));
assertThrows(IndexOutOfBoundsException.class, () -> list.get(-1));
assertThrows(IndexOutOfBoundsException.class, () -> list.get(list.size()));
}
@Test
void toStringTest() {
assertEquals("[]", newEmptyLazyList().toString());
@ -423,6 +432,11 @@ final class LazyListTest {
);
}
static Stream<List> lazyLists() {
return IntStream.rangeClosed(0, SIZE)
.mapToObj(i -> List.ofLazy(i, IDENTITY));
}
static List<Integer> newLazyList() {
return List.ofLazy(SIZE, IDENTITY);
}