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

TabObservableList.reorder changes content of filtered list

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      base.reorder(x, y) changes content of a filteredList fl build on tabPane.getTabs()



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Tab lib1 = new Tab("lib1");
      Tab lib2 = new Tab("lib2");
      Tab other = new Tab("other");

      TabPane tabPane = new TabPane(lib1, other, lib2);
      TabObservableList<Tab> base = (TabObservableList) tabPane.getTabs();

      FilteredList<Tab> filtered = new FilteredList<>(base, tab -> tab.getText().startsWith("lib"));

      base.reorder(lib1, other);

      // following outputs "true", but should be "false"
      System.out.println(other == filtered.getFirst());


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      filtered is list of lib1, lib2
      ACTUAL -
      filtered is list of other, lib2

      ---------- BEGIN SOURCE ----------
      package org.jabref.gui.javafx;

      import java.util.List;

      import javafx.collections.transformation.FilteredList;
      import javafx.scene.control.Tab;
      import javafx.scene.control.TabPane;

      import com.sun.javafx.scene.control.TabObservableList;
      import org.junit.jupiter.api.Test;
      import org.junit.jupiter.api.extension.ExtendWith;
      import org.testfx.framework.junit5.ApplicationExtension;

      import static org.junit.jupiter.api.Assertions.assertEquals;
      import static org.junit.jupiter.api.Assertions.assertNotEquals;

      @ExtendWith(ApplicationExtension.class)
      public class TabObservableListFilteredTest {

          @Test
          public void filteredListDetectsPermutation() {
              Tab lib1 = new Tab("lib1");
              Tab lib2 = new Tab("lib2");
              Tab other = new Tab("other");

              TabPane tabPane = new TabPane(lib1, other, lib2);
              TabObservableList<Tab> base = (TabObservableList) tabPane.getTabs();

              FilteredList<Tab> filtered = new FilteredList<>(base, tab -> tab.getText().startsWith("lib"));

              assertEquals(List.of(lib1, lib2), filtered);

              base.reorder(lib1, other);

              assertNotEquals(other, filtered.getFirst()); // This should not fail

              assertEquals(List.of(lib2, lib1), filtered);
          }
      }

      ---------- END SOURCE ----------

        1. TabObservableListFilteredTest.java
          2 kB
          Kevin Rushforth

            arapte Ambarish Rapte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: