JDK-7048204 : NPE from NimbusLookAndFeel.addDefault
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2011-05-25
  • Updated: 2011-07-18
  • Resolved: 2011-07-18
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 b145Fixed
Related Reports
Relates :  
Description
When I start a NetBeans 7.1 development build using JDK 7b143 using Nimbus L&F, the following exception is thrown:

java.lang.NullPointerException
	at javax.swing.plaf.nimbus.NimbusLookAndFeel.addDefault(NimbusLookAndFeel.java:593)
	at javax.swing.plaf.nimbus.NimbusLookAndFeel.access$700(NimbusLookAndFeel.java:64)
	at javax.swing.plaf.nimbus.NimbusLookAndFeel$DefaultsListener.propertyChange(NimbusLookAndFeel.java:608)
	at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
	at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
	at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:92)
	at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
	at javax.swing.UIDefaults.firePropertyChange(UIDefaults.java:844)
	at javax.swing.UIDefaults.put(UIDefaults.java:348)
	at org.netbeans.swing.dirchooser.Module.install(Module.java:93)
	at org.netbeans.swing.dirchooser.Module.restored(Module.java:73)
	at org.netbeans.core.startup.NbInstaller.loadCode(NbInstaller.java:426)
[catch] at org.netbeans.core.startup.NbInstaller.load(NbInstaller.java:366)

Comments
EVALUATION Minimal test case: import java.awt.EventQueue; import javax.swing.JLabel; import javax.swing.UIDefaults; import javax.swing.UIManager; public class NimbusBug { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @SuppressWarnings("ResultOfObjectAllocationIgnored") public @Override void run() { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Exception x) { x.printStackTrace(); } new JLabel(); UIDefaults uid = UIManager.getDefaults(); uid.putDefaults(new Object[0]); uid.put("what.ever", "else"); } }); } private NimbusBug() {} } => Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.plaf.nimbus.NimbusLookAndFeel.addDefault(NimbusLookAndFeel.java:593) at javax.swing.plaf.nimbus.NimbusLookAndFeel.access$700(NimbusLookAndFeel.java:64) at javax.swing.plaf.nimbus.NimbusLookAndFeel$DefaultsListener.propertyChange(NimbusLookAndFeel.java:608) at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327) at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:92) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263) at javax.swing.UIDefaults.firePropertyChange(UIDefaults.java:844) at javax.swing.UIDefaults.put(UIDefaults.java:348) at NimbusBug$1.run(NimbusBug.java:18)
26-05-2011

EVALUATION It doesn't seem to be possible to create a runnable test case based on the description, Netbeans is a large project and it'll take lot of time for me to understand how NbInstaller works. Please minimize the test case. Make sure that you don't access UIDefaults from multiple threads.
26-05-2011

EVALUATION Reproduction is easy. Just get a copy of NetBeans (I used a 7.1 development build but probably 7.0 works just as well) and run .../bin/netbeans --jdkhome .../jdk7 --laf Nimbus and the exception will be thrown (shown in console when not using a release build; $userdir/var/log/messages; and a flashing red icon which when clicked pops open stack trace). I encountered the problem in b143 but it has been reported by someone else in b135. I do not know in which build it first appeared; I do not have the apparatus to bisect it. It does not appear in 6u25, so it is a regression in JDK 7. As to the calling thread, currently this is not EQ, but wrapping the affected code block in EventQueue.invokeLater does not prevent the NPE, so I do not think it is a threading issue. The key is "FileChooserUI" and the value is the Class object for org.netbeans.swing.dirchooser.DelegatingChooserUI (a class with a public static ComponentUI createUI(JComponent) method); an alternate file chooser is being installed.
25-05-2011

EVALUATION Lot's of information is missing - what do you exactly do to reproduce the problem? - in what JDK build this problem starts to appear? (you mentioned b143 when the description on netbeans.org tells b135) - does this problem reliably reproducible? - any evaluation from the Netbeans side is very welcome (making sure that your code use Swing on EDT, naming the exact property which produces the exception etc...) CR is incomplete
25-05-2011

SUGGESTED FIX The source line throwing the exception: Map<String, Object> keys = compiledDefaults.get(prefix); should perhaps be: Map<String, Object> keys = getDefaultsForPrefix(prefix); Such a change fixes the bug in both the minimal test case and in NetBeans. The bug appears to be that DefaultsListener upon receiving a general "UIDefaults" property change clears its cache; but for other property changes it calls addDefault, which assumes without justification that the cache is currently active (definitely true if called from getDefaultsForPrefix, but not necessarily true otherwise). Other fixes along the same lines would likely work as well, e.g. adding getDefaultsForPrefix(null); immediately before addDefault(key, ev.getNewValue()); in the listener to force a missing cache to be created.
25-05-2011

PUBLIC COMMENTS Reported as: https://netbeans.org/bugzilla/show_bug.cgi?id=197150
25-05-2011