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

listIterator.hasNext() can return true for an empty ArrayList

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • core-libs
    • beta
    • x86
    • windows_98
    • Verified



      Name: jb33418 Date: 09/28/2000


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


      This bug is related to the ListIterator returned from ArrayList.listIterator().
      It occurs when the list is empty.

      The hasNext() method incorrectly returns True after a failed call to previous
      ().

      The behaviour expected is hasNext() should always return False when the
      ArrayList is empty.

      The follow code demostrates the problem;

      ArrayList list = new ArrayList();
      ListIterator i = list.listIterator();
      try {
        i.previous();
      }
      catch (NoSuchElementException e) {}

      // result should be False but is True!!
      boolean result = i.hasNext();
      (Review ID: 108017)
      ======================================================================

            kkladkosunw Konstantin Kladko (Inactive)
            jjb Josh Bloch (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: