Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8095966

ObservableListBase: incorrect handling of multiple changes within one beginChange()/endChange() block

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u20
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Labels:
    • Subcomponent:

      Description

      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);
          }
      }

        Attachments

          Activity

            People

            Assignee:
            msladecek Martin Sládeček
            Reporter:
            tmikula Tomas Mikula
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: