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

ObservableMap does not support null values in Maps

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P3
    • Resolution: Fixed
    • 7u10
    • 8
    • javafx
    • Ubuntu Linux 12.04 x86, jdk7u10, javafx 2.2.4

    Description

      If add element with null value( map.put("test", null) wasAdded() and wasRemoved() in MapChangeListener return false
      On remove this element from map (remove("teset")) listener will not be called.

      Example:


      import javafx.collections.FXCollections;
      import javafx.collections.MapChangeListener;
      import javafx.collections.MapChangeListener.Change;
      import javafx.collections.ObservableMap;


      public class TestObservableMap {
          public static void main(String[] args) {
              ObservableMap<String, Object> test = FXCollections.<String, Object>observableHashMap();
              test.addListener(new MapChangeListener<String, Object>(){

                  public void onChanged(Change<? extends String, ? extends Object> change) {
                      System.err.println("Is added: " + change.wasAdded());
                      System.err.println("Is removed: " + change.wasRemoved());
                  }

              });
              
              test.put("test", null);
              System.err.println(test.size());
              test.remove("test");
              System.err.println(test.size());
          }
      }


      Output of example:
      Is added: false
      Is removed: false
      1
      0

      Attachments

        Activity

          People

            msladecek Martin Sládeček
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: