diff --git a/modules/javafx.base/src/main/java/com/sun/javafx/collections/VetoableListDecorator.java b/modules/javafx.base/src/main/java/com/sun/javafx/collections/VetoableListDecorator.java index 2b73be7bfc3..1fd8b318851 100644 --- a/modules/javafx.base/src/main/java/com/sun/javafx/collections/VetoableListDecorator.java +++ b/modules/javafx.base/src/main/java/com/sun/javafx/collections/VetoableListDecorator.java @@ -134,8 +134,8 @@ private void removeFromList(List backingList, int offset, Collection col, toBeRemoved[pointer + 2] = offset + i + 1; pointer += 2; } else { - if (toBeRemoved[pointer - 1] == offset + i) { - toBeRemoved[pointer - 1] = offset + i + 1; + if (toBeRemoved[pointer] == offset + i) { + toBeRemoved[pointer] = offset + i + 1; } else { int[] tmp = new int[toBeRemoved.length + 2]; System.arraycopy(toBeRemoved, 0, tmp, 0, toBeRemoved.length); diff --git a/modules/javafx.base/src/test/java/test/javafx/collections/VetoableObservableListTest.java b/modules/javafx.base/src/test/java/test/javafx/collections/VetoableObservableListTest.java index a5026ff1443..1de34d2f925 100644 --- a/modules/javafx.base/src/test/java/test/javafx/collections/VetoableObservableListTest.java +++ b/modules/javafx.base/src/test/java/test/javafx/collections/VetoableObservableListTest.java @@ -233,12 +233,36 @@ public void testRemove_indexed() { public void testRemoveAll() { list.removeAll(Arrays.asList("bar", "eggs", "foobar")); assertSingleCall(new String[0], new int[] {1,2,3,4}); + + list.setAll("a", "b", "c", "d", "e", "f"); + calls.clear(); + list.removeAll(List.of("b", "c", "d")); + assertEquals(List.of("a", "e", "f"), list); + assertSingleCall(new String[0], new int[] {1, 4}); + + list.setAll("a", "b", "c", "d", "e", "f"); + calls.clear(); + list.removeAll(List.of("a", "b", "d", "e", "f")); + assertEquals(List.of("c"), list); + assertSingleCall(new String[0], new int[] {0, 2, 3, 6}); } @Test public void testRetainAll() { list.retainAll(Arrays.asList("foo", "barfoo", "ham")); assertSingleCall(new String[0], new int[] {1,2,3,4}); + + list.setAll("a", "b", "c", "d", "e", "f"); + calls.clear(); + list.retainAll(List.of("a", "f")); + assertEquals(List.of("a", "f"), list); + assertSingleCall(new String[0], new int[] {1, 5}); + + list.setAll("a", "b", "c", "d", "e", "f"); + calls.clear(); + list.retainAll(List.of("c")); + assertEquals(List.of("c"), list); + assertSingleCall(new String[0], new int[] {0, 2, 3, 6}); } @Test