Uploaded image for project: 'Pivot'
  1. Pivot
  2. PIVOT-484

ArrayList.ItemIterator.remove() advances the iterator

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.4, 1.5
    • 1.5
    • core-collections
    • None

    Description

      The remove() method of ArrayListItemIterator doesn't move the pointer back one item. After remove() your only option is to call next(), but the implementation of ArrayListItemIterator moves to second next item instead of the item which comes after the removed one. So it is impossible to iterate to the item which comes immediately after the removed item.

      The following code illustrates this (run with "-ea"):

      public class ArrayListTest {
      public static void main(String[] args)

      { java.util.ArrayList<String> javaList = new java.util.ArrayList<String>(); javaList.add("first"); javaList.add("second"); javaList.add("third"); Iterator<String> iterator = javaList.iterator(); String s = iterator.next(); assert s.equals("first"); iterator.remove(); s = iterator.next(); System.out.println("Java ArrayList: next is: " + s); assert s.equals("second"); org.apache.pivot.collections.ArrayList<String> pivotList = new org.apache.pivot.collections.ArrayList<String>(); pivotList.add("first"); pivotList.add("second"); pivotList.add("third"); iterator = pivotList.iterator(); s = iterator.next(); assert s.equals("first"); iterator.remove(); s = iterator.next(); System.out.println("Pivot ArrayList: next is: " + s); assert s.equals("second"); // fail, got: "third" }

      }

      I didn't check the other Iterator implementations.

      Attachments

        Activity

          People

            Unassigned Unassigned
            dmoebius Dirk Moebius
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: