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

ListSet: addAll() and removeAll() unexpected behavior #2

Open
scottfones opened this issue Nov 5, 2021 · 0 comments
Open

ListSet: addAll() and removeAll() unexpected behavior #2

scottfones opened this issue Nov 5, 2021 · 0 comments

Comments

@scottfones
Copy link

In using the ListSet#addAll(Collection<? extends T> c) we've run into unexpected behavior where only the first element of the collection c is added. We've encountered similar behavior in the ListSet#removeAll(Collection<?> c) method, except it seems to hang. We think both are due to a short circuit in the logical OR the methods employ.

Test class to reproduce:

class ListSetTest {

    private ListSet<Object> listSet;

    private Object objA;
    private Object objB;
    private Object objC;

    private Set<Object> testSet;

    @BeforeEach
    void init() {
        listSet = new ListSet<>();

        objA = new Object();
        objB = new Object();
        objC = new Object();

        testSet = new HashSet<>(Arrays.asList(objA, objB, objC));
    }

    @Test
    @Disabled("Seems to have a conditional short circuit")
    void testAddAll() {
        listSet.addAll(testSet); // only adds first
        assertEquals(3, listSet.size()); // 1
    }

    @Test
    @Disabled("Loops: Seems to have a conditional short circuit")
    void testRemoveAll() {
        listSet.add(objA);
        listSet.add(objB);
        listSet.add(objC);
        listSet.removeAll(testSet); // hangs
        assertEquals(0, listSet.size());
    }
}
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