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

javafx.beans.property.SimpleMapProperty with multiple addListeners does not call them.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 8, 9
    • javafx
    • Windows 7 64-bit

      Adding a second listener to the Java SimpleMapProperty causes neither one to respond.

      import javafx.beans.property.MapProperty;
      import javafx.beans.property.SimpleMapProperty;
      import javafx.collections.FXCollections;

      public final class MapPropertyInitialization {

          public static void main(final String[] args) {
              final MapProperty<String, String> mp =
                      new SimpleMapProperty<String, String>(
                              FXCollections.observableHashMap());

              mp.addListener((obv1, ov1, nv1) -> {
                  System.out.format("1: mp: %s%n", nv1);
              });
              mp.put("key 1", "object 1");

              mp.addListener((obv2, ov2, nv2) -> {
                  System.out.format("2: mp: %s%n", nv2);
              });
              mp.put("key 2", "object 2");
          }
      }


      Should print:

      1: mp: {key1=object1}
      1: mp: {key2=object2, key1=object1}
      2: mp: {key2=object2, key1=object1}

      But only the first line shows up.

      Adding an empty MapChangeListener corrects the problem.

      mp.addListener(new MapChangeListener<String, String>() {
          @Override
          public void onChanged(Change<? extends String, ? extends String> map) {}
      });

            jdv Jayathirth D V
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Imported: