Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8329089

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 23
    • None
    • core-libs
    • None

    Description

      According to the specifications:

      "Elements cannot be added, removed, or replaced. Calling any mutator method on the List will always cause {@code UnsupportedOperationException} to be thrown."

      However, calling `removeFirst()` or `removeLast()` on an empty immutable list will erroneously throw `java.util.NoSuchElementException` instead.

      Reproducer:

      assertThrows(UnsupportedOperationException.class, List.of()::removeFirst);

      Attachments

        Issue Links

          Activity

            People

              pminborg Per-Ake Minborg
              pminborg Per-Ake Minborg
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: