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

LinkedList.iterator().remove() throws exception of wrong type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • core-libs
    • beta2
    • generic
    • generic
    • Verified



      Name: ssT124754 Date: 04/09/2001


      java version "1.3.1-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-beta-b15)
      Java HotSpot(TM) Client VM (build 1.3.1beta-b15, mixed mode)


      Following code should make java.util.LinkedList throwing an
      IllegalStateException, but it throws NoSuchElementException.
      This is no serious bug, but affects test suites, which are
      checking if thrown exceptions are meeting the specification.

      public class LinkedListBugExample
      {
      public static void main(String[] args)
      {
          LinkedList l = new LinkedList();
          for (int i = 0; i < 100; i++) {
             l.add(new Integer(i));
          }
          Iterator it = l.iterator();
          while (it.hasNext()) {
            it.next();
            it.remove();
          }
          try {
            it.remove();
          } catch (IllegalStateException ex) {
            System.out.println("Expected exception thrown - bug not present.");
          } catch (NoSuchElementException ex) {
            System.out.println("Wrong exception thrown like specified in bug
      report.");
          }
        }
      }
      (Review ID: 120373)
      ======================================================================

            jjb Josh Bloch (Inactive)
            ssultanasunw Shaheen Sultana (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: