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

PropertyChangeSupport.firePropertyChange() notifies when oldVal == newVal ==null

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.0, 6, 6u10
    • client-libs
    • x86
    • linux, windows_xp



      Name: gm110360 Date: 10/15/2002


      FULL PRODUCT VERSION :
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The API documentation for the
      java.beans.PropertyChangeSupport.firePropertyChange(...)
      methods states that:
      "No event is fired if old and new are equal and non-null."

      This causes a bogus event to be fired if both old and new
      are null.
      The current sematics therefore makes it impossible to
      solely rely on the event devliery mechanism to detect
      property changes. One must check that the delivered event
      really describes a change.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The expected result is that the test program creates no
      output.
      Insead the following is produced:
      oldValue=null
      newValue=null


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class PropertyChangeTest implements java.beans.PropertyChangeListener {

          PropertyChangeTest() {
              java.beans.PropertyChangeSupport p = new
      java.beans.PropertyChangeSupport(this);
              p.addPropertyChangeListener( this );
              p.firePropertyChange( "dummy", null, null );
              p.firePropertyChange( "dummy", "hello", "hello" );
          }
          
          public void propertyChange( java.beans.PropertyChangeEvent event ) {
              System.err.println( "oldValue="+event.getOldValue() );
              System.err.println( "newValue="+event.getNewValue() );
          }
          
          public static void main(String[] args) {
              new PropertyChangeTest();
          }
          
      }
      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Change the listeners to check for oldValue == newValue.

      public void propertyChange( PropertyChangeEvent event ) {
          if ( event.getOldValue() == null
            && event.getNewValue() == null )
          {
              return;
          }

          // ...

      }
      (Review ID: 165789)
      ======================================================================

            mdavidsosunw Mark Davidson (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: