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

Inconsistent handling of InvalidationListener notifications added to property

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      In JavaFX, the InvalidationListener added to properties is notified inconsistently.
      Looking at EXAMPLE ONE, changing the value of a StringProperty, which itself is the property of a TextField, will notify the InvalidationListener every time the value changes.
      Looking at EXAMPLE TWO, changing the value of a StringProperty, which is created as SimpleStringProperty, will notify the InvalidationListener only at the first change and after StringProperty.get() has been called. This is utterly confusing and should be considered a bug, since the only difference for the user is that one StringProperty is part of the TextField, the other is not.


      ////// EXAMPLE ONE

      TextField tf = new TextField();
      StringProperty sp = tf.textProperty();

      sp.addListener(_ -> System.out.println("invalid") );

      sp.set("One"); // prints "invalid"
      sp.set("Two"); // prints "invalid"
      sp.set("Three"); // prints "invalid"

      sp.get();

      out("Four"); // prints "invalid"
      out("Five"); // prints "invalid"
      out("Six"); // prints "invalid"

      ////// EXAMPLE ONE



      ////// EXAMPLE TWO

      StringProperty sp = new SimpleStringProperty();

      sp.addListener(_ -> System.out.println("invalid") );

      sp.set("One"); // prints "invalid"
      sp.set("Two"); // does not print anything
      sp.set("Three"); // does not print anything

      sp.get();

      sp.set("Four"); // prints "invalid"
      sp.set("Five"); // does not print anything
      sp.set("Six"); // does not print anything

      ////// EXAMPLE TWO


            adev Anupam Dev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: