JDK-4279894 : JComponent.getListeners() does not work for PropertyChangeListeners
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 1999-10-11
  • Updated: 2000-04-27
  • Resolved: 2000-04-27
Related Reports
Duplicate :  
Description

Name: asC58863			Date: 10/11/99


(See JavaDoc comments)
"public EventListener[] getListeners(Class listenerType)
     Return an array of all the listeners that were added to this JComponent with
     addXXXListener(), where XXX is the name of the listenerType argument.
[...]
     If no such listener list exists, then an empty array is returned.
"

Here is the example demonstrating the bug:
------------------   Test.java -----------------
import javax.swing.*;
import java.beans.*;

public class Test {
    public static void main(String[] argv) {
        JList c = new JList();
        StubPropertyChangeListener pcl1 = new StubPropertyChangeListener();
        StubPropertyChangeListener pcl2 = new StubPropertyChangeListener();
        StubPropertyChangeListener pcl3 = new StubPropertyChangeListener();
        c.addPropertyChangeListener(pcl1);
        c.addPropertyChangeListener(pcl2);
        c.addPropertyChangeListener(pcl3);
        System.out.println(" "+c.getListeners(StubPropertyChangeListener.class).length);
        System.exit(0);
    }
}
class StubPropertyChangeListener implements PropertyChangeListener {
    public void propertyChange(PropertyChangeEvent pce) {
    }
}
-------------- Output from the test  -----------------
 0
------------------------------------------------------ 

As it seen from the source code, listenerList is never used except
this method. It seems to me listenerList.add(XXXListener.class) 
should be invoked at the end of each JComponent.addXXXListener() 
method to let getListeners() method works properly.

======================================================================

Comments
EVALUATION This will be implemented in the awt class Component ... transferring. philip.milne@eng 2000-02-25
25-02-2000