Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement of Iterator_RemoveOnce #238

Open
emopers opened this issue Apr 29, 2016 · 0 comments
Open

Improvement of Iterator_RemoveOnce #238

emopers opened this issue Apr 29, 2016 · 0 comments

Comments

@emopers
Copy link

emopers commented Apr 29, 2016

For property Iterator_RemoveOnce, we noticed that it would give false alarms on ListIterator if the ListIterator used previous() to move the iterator. Following is one snippet illustrating how JavaMOP can raise alarms while the program is legal:

import java.util.ArrayList;
import java.util.ListIterator;

public class Iterator_RemoveOnce {
    public static void main(String[] args) {
        ArrayList<Integer> arr = new ArrayList<Integer>();
        for(int i = 0; i < 10; i++) {
            arr.add(i);
        }
        ListIterator<Integer> it = arr.listIterator(arr.size());
        while(it.hasPrevious()) {
            it.previous();
            it.remove();
        }
    }
}

This operation is allowed in property ListIterator_RemoveOnce, but as ListIterator is a subclass of Iterator, it is still considered illegal by Iterator_RemoveOnce. We suggest to have Iterator_RemoveOnce property to exclude ListIterator, as there is already a good property specifically for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant