Skip to content

Commit

Permalink
8329089: Empty immutable list throws the wrong exception type for rem…
Browse files Browse the repository at this point in the history
…ove(first | last) operations

Reviewed-by: rriggs
  • Loading branch information
minborg committed Apr 5, 2024
1 parent 1131bb7 commit b71acc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ abstract static class AbstractImmutableList<E> extends AbstractImmutableCollecti
@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(); }
Expand Down
7 changes: 7 additions & 0 deletions test/jdk/java/util/Collection/MOAT.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public static void realMain(String[] args) {
testCollection(list);
testImmutableList(list);
testListMutatorsAlwaysThrow(list);
testImmutableListMutatorsAlwaysThrow(list);
if (list.size() >= 1) {
// test subLists
List<Integer> headList = list.subList(0, list.size() - 1);
Expand Down Expand Up @@ -564,6 +565,12 @@ private static void testListMutatorsAlwaysThrow(List<Integer> c) {
() -> 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.
*
Expand Down

1 comment on commit b71acc7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.