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

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 1.4.0
    • Affects Version/s: 1.3.0
    • Component/s: 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)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: