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

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 23
    • Affects Version/s: None
    • Component/s: core-libs
    • None

      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);

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

              Created:
              Updated:
              Resolved: