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

ChangeListener not executed

XMLWordPrintable

    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java version "1.8.0_111"
      Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux Mint 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:42:33 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      If you register more than one ChangeListener to a class, which uses the com.sun.javafx.binding.MapExpressionHelper ( e.g. SimpleMapProperty), then the registered ChangeListeners will not be executed.

      If only one ChangeListener is used all works as expected because it uses the inner class SingleChange.
      But with two or more Listeners the inner class Generic is used, which has a bug within the method:

      protected void fireValueChangedEvent(final MapChangeListener.Change<? extends K, ? extends V> change)

      This methods checks the variable mapChangeSize to be > 0, but this is only the case if a MapChangeListener is present. If no MapChangeListener is present this variable will be 0 and thus the normal ChangeListener will not be executed too.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a SimpleMapProperty.
      Register 2 or more normal ChangeListeners.
      Make some changes (e.g. a put) on the map.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      All ChangeListeners will be executed for each change.
      ACTUAL -
      No ChangeListener will be executed.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.beans.property.MapProperty;
      import javafx.beans.property.SimpleMapProperty;
      import javafx.collections.FXCollections;


      public class Main {
          
          
          public static void main(String[] args) {
              MapProperty<String, String> mapProperty = new SimpleMapProperty<>(FXCollections.observableHashMap());
              
              
              // Using line a only work as expected. Output: "ChangeListener"
              // Using line a and b doesn't work: No output at all
              // Using line a,b and c works again: Output: "ChangeListener" "MapChangeListener"
              
              // a
              mapProperty.addListener((obs, ov, nv) -> System.out.println("ChangeListener"));
              // b
              mapProperty.addListener((obs, ov, nv) -> {});
              // c
      // mapProperty.addListener((MapChangeListener.Change<?,?> change) -> System.out.println("MapChangeListener"));
                      
              mapProperty.get().put("Test1", "Value1");
          }
          
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      If you register a usesless and empty MapChangeListener, then all ChangeListeners will be executed again (See line 'c from the test code)

            vadim Vadim Pakhnushev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: