pivot-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dirk Moebius (JIRA)" <j...@apache.org>
Subject [jira] Updated: (PIVOT-484) ArrayList.ItemIterator.remove() advances the iterator
Date Wed, 28 Apr 2010 15:24:33 GMT

     [ https://issues.apache.org/jira/browse/PIVOT-484?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Dirk Moebius updated PIVOT-484:
-------------------------------

    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. 


  was:
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. 



> 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.
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. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message