Pivot
  1. Pivot
  2. PIVOT-484

ArrayList.ItemIterator.remove() advances the iterator

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.4, 1.5
    • Fix Version/s: 1.5
    • Component/s: core-collections
    • Labels:
      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.

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Dirk Moebius
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development