-
Bug
-
Resolution: Fixed
-
P3
-
8u20
Below is a sequence of insert, replace and remove operations on an observable list that end up being merged incorrectly into one list change when performed within one beginChange()/endChange() block. The code below even throws an IndexOutOfBoundsException because of this.
Tested with 8u20 b13.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javafx.collections.ListChangeListener.Change;
import com.sun.javafx.collections.ObservableListWrapper;
public class ObservableListBaseTest<E> extends ObservableListWrapper<E> {
public static void main(String[] args) {
ObservableListBaseTest<Integer> wrapper = new ObservableListBaseTest<>(new ArrayList<>());
wrapper.addAll(1, 4, 5, 6);
wrapper.addListener((Change<? extends Integer> change) -> {
while(change.next()) {
System.out.println("Change:");
System.out.println(" from = " + change.getFrom());
System.out.println(" removed = " + change.getRemoved());
System.out.println(" added = " + change.getAddedSubList());
}
});
wrapper.beginChange();
wrapper.addAll(1, Arrays.asList(2, 3));
wrapper.subList(4, 6).replaceAll(i -> i + 10);
wrapper.subList(2, 5).clear();
wrapper.endChange();
}
public ObservableListBaseTest(List<E> list) {
super(list);
}
}
Tested with 8u20 b13.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javafx.collections.ListChangeListener.Change;
import com.sun.javafx.collections.ObservableListWrapper;
public class ObservableListBaseTest<E> extends ObservableListWrapper<E> {
public static void main(String[] args) {
ObservableListBaseTest<Integer> wrapper = new ObservableListBaseTest<>(new ArrayList<>());
wrapper.addAll(1, 4, 5, 6);
wrapper.addListener((Change<? extends Integer> change) -> {
while(change.next()) {
System.out.println("Change:");
System.out.println(" from = " + change.getFrom());
System.out.println(" removed = " + change.getRemoved());
System.out.println(" added = " + change.getAddedSubList());
}
});
wrapper.beginChange();
wrapper.addAll(1, Arrays.asList(2, 3));
wrapper.subList(4, 6).replaceAll(i -> i + 10);
wrapper.subList(2, 5).clear();
wrapper.endChange();
}
public ObservableListBaseTest(List<E> list) {
super(list);
}
}