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

Improper use of .equals in PropertyChangeSupport.firePropertyChange

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • bdk_1.0
    • client-libs
    • generic
    • generic



      Name: mc57594 Date: 07/27/99


      I believe that firePropertyChange in PropertyChangeSupport has a
      problem. Currently, the code looks like this:

       public void firePropertyChange(String propertyName,
           Object oldValue, Object newValue) {

       if (oldValue != null && oldValue.equals(newValue)) {
           return;
       }
      etc.

      I understand section 7.4.4 of the spec. The problem with this
      implementation of it arises in a situation where I have a deep
      graph of beans. Suppose that an object, A, is listening to a
      complex property, P1, of another object, B. Within A, there is
      another listener, C, to a property of property P1. B fires P1,
      but the new instance of P1 is .equals equal to the old value of
      P1, so it doesn't fire. The result is that C is listening to
      the completely wrong object!

      For this to work with both complex object graphs and primitives,
      I propose the following change:

       public void firePropertyChange(String propertyName,
           Object oldValue, Object newValue) {

       if (oldValue != null && oldValue == newValue) {
           return;
       }
      etc.

      In most situations, this will continue to work as it currently
      does. In some cases, however, .equals will return true
      while == will return false. It is my assertion that the
      property change event should fire under these conditions, and
      the code change above will allow the event to fire.

      Thanks in advance for your consideration of this bug.
      (Review ID: 57491)
      ======================================================================

            mdavidsosunw Mark Davidson (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: