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

FilteredList fails to update correctly during permutation operations

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      When a FilteredList wraps a TabObservableList (used internally by TabPane.getTabs()), it fails to recompute its contents correctly during a tab reordering (permutation). This results in the FilteredList containing outdated elements or incorrect order. No exceptions are thrown, but the filtered list becomes semantically incorrect.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a TabPane with some tabs.

      Wrap its tab list (TabObservableList) in a FilteredList<Tab> with a predicate (e.g., tab text starts with "lib").

      Perform a permutation (reordering) on the base tab list using TabObservableList.reorder(...).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The FilteredList should automatically detect changes in order or filtering conditions and update its internal state to reflect the correct filtered view.
      ACTUAL -
      The FilteredList continues to reference an outdated view after permutation. The filtered content becomes incorrect even though the backing list changed.



      ---------- 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 testFilteredListDetectsPermutation() {
              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);

              // Perform permutation
              base.reorder(lib1, other);

              // This fails: filtered list did not update correctly
              assertNotEquals(other, filtered.get(0)); // Should hold if filter was applied correctly

              assertEquals(List.of(lib2, lib1), filtered); // Expected filtered order after permutation
          }
      }

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

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: