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

FilteredList reports a size of zero until a Predicate is supplied.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8u40
    • 8u20
    • javafx
    • Windows 8.1 64bit, JDK 8u20-b17

    Description

      Here is a sample (code below too):

      https://gist.github.com/ryanjaeb/841bb08c0c5fa1bea946

      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.collections.transformation.FilteredList;

      public class FilteredListWithoutPredicate {
          public static void main(String[] args) {
              ObservableList<String> source = FXCollections.observableArrayList();
              source.addAll("one", "two", "three");
              System.out.println("source size: " + source.size());

              System.out.println("without predicate: "
                      + new FilteredList<>(source).size());

              System.out.println("with predicate: "
                      + new FilteredList<>(source, t -> true).size());
          }
      }

      Steps to reproduce:

      1. Run the example.
      2. Observe the output.

      The output will be:

      source size: 3
      without predicate: 0
      with predicate: 3

      This contradicts the JavaDoc for the one arg constructor of FilteredList.

      The default value for the predicate property in FilteredList is the ALWAYS_TRUE predicate. The one arg constructor passes ALWAYS_TRUE as the predicate, but, since it's already ALWAYS_TRUE, the predicate property won't be invalidated.

      Passing a different instance of an always true predicate is a really simple workaround.

      Attachments

        Activity

          People

            msladecek Martin Sládeček
            rjaebjfx Ryan Jaeb (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: