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

8233179: VetoableListDecorator#sort throws IllegalArgumentException "duplicate children" #1674

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
Expand All @@ -39,7 +40,7 @@
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;

public abstract class VetoableListDecorator<E> implements ObservableList<E> {
public abstract class VetoableListDecorator<E> implements ObservableList<E>, SortableList<E> {

private final ObservableList<E> list;
private int modCount;
Expand Down Expand Up @@ -100,6 +101,20 @@ public void removeListener(InvalidationListener listener) {
helper = ListListenerHelper.removeListener(helper, listener);
}

@Override
public final void doSort(Comparator<? super E> comparator) {
var sortedList = new ArrayList<>(list);
sortedList.sort(comparator);
onProposedChange(Collections.unmodifiableList(sortedList), 0, size());
try {
modCount++;
list.setAll(sortedList);
} catch(Exception e) {
modCount--;
throw e;
}
}

@Override
public boolean addAll(E... elements) {
return addAll(Arrays.asList(elements));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -569,7 +570,14 @@ public void testSubListCreatedOnChangeValid() {
assertEquals(1, subLists.size());
subLists.get(0).size(); // Assert not throwing Exception
subLists.clear();

}

@Test
public void testSort() {
list.setAll("d", "b", "a", "c");
calls.clear();
list.sort(Comparator.naturalOrder());
assertEquals(List.of("a", "b", "c", "d"), list);
assertSingleCall(new String[] {"a", "b", "c", "d"}, new int[] {0, 4});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.sun.javafx.scene.input.PickResultChooser;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import javafx.scene.Group;
import javafx.scene.GroupShim;
Expand Down Expand Up @@ -277,6 +279,22 @@ public void testRemoveAddDiferentChild() {
assertEquals(5, ((NGGroup)NodeHelper.getPeer(g)).getChildren().size());
}

@Test
public void testSortChildren() {
Rectangle rect1 = new Rectangle();
rect1.setId("1");
Rectangle rect2 = new Rectangle();
rect2.setId("2");
Rectangle rect3 = new Rectangle();
rect3.setId("3");

Group g = new Group();
g.getChildren().addAll(rect3, rect1, rect2);
g.getChildren().sort(Comparator.comparing(node -> node.getId()));

assertEquals(List.of(rect1, rect2, rect3), g.getChildren());
}

@Test
public void testGetChildrenUnmodifiable() {
Rectangle rect1 = new Rectangle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import javafx.css.PseudoClass;
import javafx.scene.Group;
import javafx.scene.Node;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -212,7 +211,6 @@ void multipleNodes_removeInteriorRange() {
}

@Test
@Disabled("JDK-8233179")
void multipleNodes_permutation() {
var group = new Group();
var child1 = new Group();
Expand Down