diff --git a/src/java.base/share/classes/java/util/ImmutableCollections.java b/src/java.base/share/classes/java/util/ImmutableCollections.java index 525cdf15ecd..726c7bb923b 100644 --- a/src/java.base/share/classes/java/util/ImmutableCollections.java +++ b/src/java.base/share/classes/java/util/ImmutableCollections.java @@ -258,6 +258,8 @@ class ImmutableCollections { @Override public void add(int index, E element) { throw uoe(); } @Override public boolean addAll(int index, Collection 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 operator) { throw uoe(); } @Override public E set(int index, E element) { throw uoe(); } @Override public void sort(Comparator c) { throw uoe(); } diff --git a/test/jdk/java/util/Collection/MOAT.java b/test/jdk/java/util/Collection/MOAT.java index bbc332cc211..0e5eadc9799 100644 --- a/test/jdk/java/util/Collection/MOAT.java +++ b/test/jdk/java/util/Collection/MOAT.java @@ -246,6 +246,7 @@ public class MOAT { testCollection(list); testImmutableList(list); testListMutatorsAlwaysThrow(list); + testImmutableListMutatorsAlwaysThrow(list); if (list.size() >= 1) { // test subLists List headList = list.subList(0, list.size() - 1); @@ -564,6 +565,12 @@ public class MOAT { () -> c.addAll(0, Collections.emptyList())); } + private static void testImmutableListMutatorsAlwaysThrow(List c) { + THROWS(UnsupportedOperationException.class, + c::removeFirst, + c::removeLast); + } + /** * As above, for an empty list. *