Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-2526

[classlib][beans] Harmony implementation of PropertyChangeSupport.hasListeners() differs from RI's

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • None
    • None
    • winXP

    Description

      It seems there is a bug in RI implementation of the java.beans.propertyChangeSupport.hasListeners() method. It works incorrectly if PropertyChangeListenerProxy was added instead of the regular PropertyChangeListener. RI cannot find such listeners with hasListeners(). However, the getPropertyChangeListeners() returns correct value. Please see the test case below:

      ---I
      import java.beans.*;

      public class TestPropertyChangeListener {

      public static class MyBean {
      public int getProp1()

      { return 1; }

      public void setProp1(int val) {}
      }

      public static class MyListener implements PropertyChangeListener {
      public void propertyChange(PropertyChangeEvent evt) {}
      }

      public static void main(String argv[]) {
      MyBean source = new MyBean();
      final String prop = "prop1";
      PropertyChangeListener l1 = new MyListener();
      PropertyChangeListener l2 = new PropertyChangeListenerProxy(prop, new MyListener());
      PropertyChangeSupport sup;

      sup = new PropertyChangeSupport(source);
      sup.addPropertyChangeListener(prop, l1);
      System.out.println("Total listeners: " + sup.getPropertyChangeListeners(prop).length);
      if (!sup.hasListeners(prop))

      { System.out.println("FAIL at point 1"); }

      sup = new PropertyChangeSupport(source);
      sup.addPropertyChangeListener(prop, l2);
      System.out.println("Total listeners: " + sup.getPropertyChangeListeners(prop).length);
      if (!sup.hasListeners(prop))

      { System.out.println("FAIL at point 2"); }

      }
      }

      The output on RI is:
      Total listeners: 1
      Total listeners: 1
      FAIL at point 2

      Such a behavior is inconsistent and against the spec for PropertyChangeSupport class. Harmony implementation does not follow it. This test passes on Harmony.

      Attachments

        Activity

          People

            zakha Alexei Zakharov
            zakha Alexei Zakharov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: