8329089: Empty immutable list throws the wrong exception type for remove(first | last) operations

Reviewed-by: rriggs
This commit is contained in:
Per Minborg 2024-04-05 07:38:43 +00:00
parent 1131bb77ec
commit b71acc704a
2 changed files with 9 additions and 0 deletions

View File

@ -258,6 +258,8 @@ class ImmutableCollections {
@Override public void add(int index, E element) { throw uoe(); }
@Override public boolean addAll(int index, Collection<? extends E> c) { throw uoe(); }
@Override public E remove(int index) { throw uoe(); }
@Override public E removeFirst() { throw uoe(); }
@Override public E removeLast() { throw uoe(); }
@Override public void replaceAll(UnaryOperator<E> operator) { throw uoe(); }
@Override public E set(int index, E element) { throw uoe(); }
@Override public void sort(Comparator<? super E> c) { throw uoe(); }

View File

@ -246,6 +246,7 @@ public class MOAT {
testCollection(list);
testImmutableList(list);
testListMutatorsAlwaysThrow(list);
testImmutableListMutatorsAlwaysThrow(list);
if (list.size() >= 1) {
// test subLists
List<Integer> headList = list.subList(0, list.size() - 1);
@ -564,6 +565,12 @@ public class MOAT {
() -> c.addAll(0, Collections.emptyList()));
}
private static void testImmutableListMutatorsAlwaysThrow(List<Integer> c) {
THROWS(UnsupportedOperationException.class,
c::removeFirst,
c::removeLast);
}
/**
* As above, for an empty list.
*