United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 7072645 Toolkit.addPropertyChangeListener(name, pcl) throws NPE for null name
7072645 : Toolkit.addPropertyChangeListener(name, pcl) throws NPE for null name

Details
Type:
Bug
Submit Date:
2011-07-29
Status:
Closed
Updated Date:
2012-05-24
Project Name:
JDK
Resolved Date:
2012-05-24
Component:
client-libs
OS:
generic
Sub-Component:
java.awt
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
8

Related Reports
Backport:
Relates:

Sub Tasks

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
                                     
2011-08-23
EVALUATION

Should be fixed.
                                     
2011-08-09



Hardware and Software, Engineered to Work Together