JDK-7072645 : Toolkit.addPropertyChangeListener(name, pcl) throws NPE for null name
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-07-29
  • Updated: 2013-10-29
  • Resolved: 2012-05-24
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 JDK 8
7u2Fixed 8 b04Fixed
Related Reports
Relates :  
Description
Method java.awt.Toolkit.addPropertyChangeListener() says:

    /**
     ...
     * If {@code name} is {@code null} or {@code pcl} is {@code null},
     * no exception is thrown and no action is performed.
     ...
     */
    public void addPropertyChangeListener(String name, PropertyChangeListener pcl)

The assertion about null name is not satisfied by Windows/XToolkits.


The following code sample:
--------------------------------------------------------------------------------------------------
import java.awt.*;
import java.beans.*;

public class AddPCL_NPE {
    public static void main(String[] args) {
        Toolkit.getDefaultToolkit().addPropertyChangeListener(null, new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {   }
        });
    }
}

--------------------------------------------------------------------------------------------------

will produce output like:

Exception in thread "main" java.lang.NullPointerException
	at sun.awt.windows.WDesktopProperties.isWindowsProperty(WDesktopProperties.java:77)
	at sun.awt.windows.WToolkit.addPropertyChangeListener(WToolkit.java:882)

or

java.lang.NullPointerException
	at sun.awt.X11.XToolkit.initXSettingsIfNeeded(XToolkit.java:1546)
	at sun.awt.X11.XToolkit.addPropertyChangeListener(XToolkit.java:1535)

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/awt_data/8/7072645
23-08-2011

EVALUATION Should be fixed.
09-08-2011