ArrayList.ItemIterator.remove() advances the iterator
-----------------------------------------------------
Key: PIVOT-484
URL: https://issues.apache.org/jira/browse/PIVOT-484
Project: Pivot
Issue Type: Bug
Components: core-collections
Affects Versions: 1.4, 1.5
Reporter: Dirk Moebius
The remove() method of ArrayListItemIterator doesn't move the pointer back one
item. Users of ArrayList.ItemIterator who call remove() have only the option to
call next(), which advances to the second next item, so it is impossible to
step 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.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.