JDK-7020922 : java.awt.Toolkit.getPropertyChangeListeners() should mention that it returns proxies
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-02-20
  • Updated: 2017-05-16
  • Resolved: 2011-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b142Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Platform: All
JDK: 1.4+
class: java.awt.Toolkit
method: http://download.java.net/jdk7/docs/api/java/awt/Toolkit.html#getPropertyChangeListeners()

    --------------------------------------------------------------------------------
    public PropertyChangeListener[] getPropertyChangeListeners()
    Returns an array of all the property change listeners registered on this toolkit.
    Returns:
          all of this toolkit's PropertyChangeListeners or an empty array 
          if no property change listeners are currently registered
    --------------------------------------------------------------------------------

 Assertion above is not correct. 
 In fact method returns proxies, not listeners.

 Please see the following code sample for illustration:

----------------------------------------------------------------------------------------------
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) {

        // this is for shortness, this behavior exist in default methods of Toolkit class
        // so any stubbed Toolkit child could be used as well
        Toolkit toolkit = Toolkit.getDefaultToolkit();

        toolkit.addPropertyChangeListener("prop", new PropertyChangeListener() {
            @Override public void propertyChange(PropertyChangeEvent evt) {   }
            @Override public String toString() { return "my pcl"; }
        });

        PropertyChangeListener[] byProp = toolkit.getPropertyChangeListeners("prop");
        PropertyChangeListener[] all = toolkit.getPropertyChangeListeners();

        System.out.println("getPropertyChangeListeners(\"prop\") = " + Arrays.toString(byProp));
        System.out.println("getPropertyChangeListeners() = " + Arrays.toString(all));
    }
}
----------------------------------------------------------------------------------------------

The output will look like

getPropertyChangeListeners("prop") = [my pcl]
getPropertyChangeListeners() = [java.beans.PropertyChangeListenerProxy@17ec251]

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/awt_data/7/7020922/
27-04-2011

EVALUATION Should be fixed.
27-04-2011