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

FXCollections.unmodifiableObservableList fails after a GC run

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 9
    • 8u20
    • javafx
    • None

      FXCollections fails if one does to keep the resulting collection referenced in memory

      package application;

      import javafx.collections.FXCollections;
      import javafx.collections.ListChangeListener;
      import javafx.collections.ObservableList;

      public class TestUnmodified {
      public TestUnmodified() {
      ObservableList<String> s = FXCollections.observableArrayList();
      FXCollections.unmodifiableObservableList(s).addListener(new ListChangeListener<String>() {

      @Override
      public void onChanged(
      javafx.collections.ListChangeListener.Change<? extends String> c) {
      TestUnmodified.this.call(c);
      }
      });
      s.setAll("A1");
      s.setAll("A2");
      System.gc();
      s.setAll("A3");
      }

      private void call(javafx.collections.ListChangeListener.Change<? extends String> c) {
      System.err.println("MODIFIED " + c);
      }

      public static void main(String[] args) {
      new TestUnmodified();
      }
      }

      The only current fix and also reason e.g. Parent#getChildrenUnmodifiable is not affected is to keep the wrapped list in an instance variable

            vadim Vadim Pakhnushev
            tschindl Tom Schindl
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: