Недавно я получил странную трассировку стека в логах netbeans (я добавил ее в конец этого поста). Я был в состоянии отследить это до LAF. Эта ошибка возникает при запуске Netbeans с использованием GTK LAF, но отлично работает в Metal и с использованием собственного Windows LAF.
Кажется, что экземпляр PropertyChangeSupport имеет значение NULL, поэтому он добавляет ошибку при добавлении прослушивателя изменения свойства. Вот сокращенный источник моего пользовательского компонента:
public class EnterprisePicker extends javax.swing.JPanel implements ActionListener, KeyListener, ListSelectionListener, UnitContainer {
private static final Logger logger = IdeUiUtil.initLogger(EnterprisePicker.class.getName());
protected InfoPanelStyle infoPanelStyle = InfoPanelStyle.FULL;
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public static final String PROP_INFOPANELSTYLE = "infoPanelStyle";
/** Creates the new component */
public EnterprisePicker() {
// [... snip ...]
}
// [ ... snip ... ]
/**
* Add PropertyChangeListener.
*
* @param listener
*/
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(listener);
}
// [ ... snip ... ]
}
Очевидно, я мог бы просто защитить эти вызовы, используя if (propertyChangeSupport == null)
... Но разве это не нарушило бы свойства позже в приложении? Предполагая, что ни один слушатель никогда не будет подключен, так как экземпляр null
...?
Трассировка стека
INFO [org.netbeans.modules.form.BeanSupport]: Cannot create default instance of: org.statec.ide.ui.components.EnterprisePicker
java.lang.NullPointerException
at org.statec.ide.ui.components.EnterprisePicker.addPropertyChangeListener(EnterprisePicker.java:654)
at javax.swing.plaf.synth.SynthPanelUI.installListeners(SynthPanelUI.java:49)
at javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:38)
at javax.swing.JComponent.setUI(JComponent.java:662)
at javax.swing.JPanel.setUI(JPanel.java:136)
at javax.swing.JPanel.updateUI(JPanel.java:109)
at javax.swing.JPanel.<init>(JPanel.java:69)
at javax.swing.JPanel.<init>(JPanel.java:92)
at javax.swing.JPanel.<init>(JPanel.java:100)
at org.statec.ide.ui.components.EnterprisePicker.<init>(EnterprisePicker.java:39)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.netbeans.modules.form.CreationFactory.createDefaultInstance(CreationFactory.java:168)
[catch] at org.netbeans.modules.form.BeanSupport.createBeanInstance(BeanSupport.java:83)
at org.netbeans.modules.form.BeanSupport.getDefaultInstance(BeanSupport.java:109)
at org.netbeans.modules.form.GandalfPersistenceManager.restoreComponent(GandalfPersistenceManager.java:769)
at org.netbeans.modules.form.GandalfPersistenceManager.loadComponent(GandalfPersistenceManager.java:1007)
at org.netbeans.modules.form.GandalfPersistenceManager.loadForm(GandalfPersistenceManager.java:527)
at org.netbeans.modules.form.GandalfPersistenceManager.loadForm(GandalfPersistenceManager.java:299)
at org.netbeans.modules.form.FormEditor$3.run(FormEditor.java:337)
at org.netbeans.modules.form.FormLAF$2.run(FormLAF.java:293)
at org.openide.util.Mutex.doEventAccess(Mutex.java:1361)
at org.openide.util.Mutex.readAccess(Mutex.java:320)
at org.netbeans.modules.form.FormLAF.executeWithLookAndFeel(FormLAF.java:276)
at org.netbeans.modules.form.FormEditor.loadFormData(FormEditor.java:334)
at org.netbeans.modules.form.FormEditor.loadFormDesigner(FormEditor.java:232)
at org.netbeans.modules.form.FormDesigner.finishComponentShowing(FormDesigner.java:1932)
at org.netbeans.modules.form.FormDesigner.access$1100(FormDesigner.java:107)
at org.netbeans.modules.form.FormDesigner$PreLoadTask$1.run(FormDesigner.java:1897)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:148)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
INFO
org.openide.ErrorManager$AnnException: msg
at org.openide.ErrorManager$AnnException.findOrCreate(ErrorManager.java:866)
at org.openide.ErrorManager$DelegatingErrorManager.annotate(ErrorManager.java:653)
at org.netbeans.modules.form.GandalfPersistenceManager.annotateException(GandalfPersistenceManager.java:237)
at org.netbeans.modules.form.GandalfPersistenceManager.annotateException(GandalfPersistenceManager.java:247)
at org.netbeans.modules.form.GandalfPersistenceManager.restoreComponent(GandalfPersistenceManager.java:865)
at org.netbeans.modules.form.GandalfPersistenceManager.loadComponent(GandalfPersistenceManager.java:1007)
at org.netbeans.modules.form.GandalfPersistenceManager.loadForm(GandalfPersistenceManager.java:527)
at org.netbeans.modules.form.GandalfPersistenceManager.loadForm(GandalfPersistenceManager.java:299)
at org.netbeans.modules.form.FormEditor$3.run(FormEditor.java:337)
at org.netbeans.modules.form.FormLAF$2.run(FormLAF.java:293)
at org.openide.util.Mutex.doEventAccess(Mutex.java:1361)
at org.openide.util.Mutex.readAccess(Mutex.java:320)
at org.netbeans.modules.form.FormLAF.executeWithLookAndFeel(FormLAF.java:276)
at org.netbeans.modules.form.FormEditor.loadFormData(FormEditor.java:334)
at org.netbeans.modules.form.FormEditor.loadFormDesigner(FormEditor.java:232)
at org.netbeans.modules.form.FormDesigner.finishComponentShowing(FormDesigner.java:1932)
at org.netbeans.modules.form.FormDesigner.access$1100(FormDesigner.java:107)
at org.netbeans.modules.form.FormDesigner$PreLoadTask$1.run(FormDesigner.java:1897)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:148)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
msg
Caused: java.lang.NullPointerException
at org.statec.ide.ui.components.EnterprisePicker.addPropertyChangeListener(EnterprisePicker.java:654)
at javax.swing.plaf.synth.SynthPanelUI.installListeners(SynthPanelUI.java:49)
at javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:38)
at javax.swing.JComponent.setUI(JComponent.java:662)
at javax.swing.JPanel.setUI(JPanel.java:136)
at javax.swing.JPanel.updateUI(JPanel.java:109)
at javax.swing.JPanel.<init>(JPanel.java:69)
at javax.swing.JPanel.<init>(JPanel.java:92)
at javax.swing.JPanel.<init>(JPanel.java:100)
at org.statec.ide.ui.components.EnterprisePicker.<init>(EnterprisePicker.java:39)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.netbeans.modules.form.CreationFactory.createDefaultInstance(CreationFactory.java:168)
at org.netbeans.modules.form.RADComponent.createBeanInstance(RADComponent.java:252)
at org.netbeans.modules.form.RADComponent.initInstance(RADComponent.java:191)
at org.netbeans.modules.form.GandalfPersistenceManager.restoreComponent(GandalfPersistenceManager.java:851)
at org.netbeans.modules.form.GandalfPersistenceManager.loadComponent(GandalfPersistenceManager.java:1007)
at org.netbeans.modules.form.GandalfPersistenceManager.loadForm(GandalfPersistenceManager.java:527)
at org.netbeans.modules.form.GandalfPersistenceManager.loadForm(GandalfPersistenceManager.java:299)
at org.netbeans.modules.form.FormEditor$3.run(FormEditor.java:337)
at org.netbeans.modules.form.FormLAF$2.run(FormLAF.java:293)
at org.openide.util.Mutex.doEventAccess(Mutex.java:1361)
at org.openide.util.Mutex.readAccess(Mutex.java:320)
at org.netbeans.modules.form.FormLAF.executeWithLookAndFeel(FormLAF.java:276)
at org.netbeans.modules.form.FormEditor.loadFormData(FormEditor.java:334)
[catch] at org.netbeans.modules.form.FormEditor.loadFormDesigner(FormEditor.java:232)
at org.netbeans.modules.form.FormDesigner.finishComponentShowing(FormDesigner.java:1932)
at org.netbeans.modules.form.FormDesigner.access$1100(FormDesigner.java:107)
at org.netbeans.modules.form.FormDesigner$PreLoadTask$1.run(FormDesigner.java:1897)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:148)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Error in loading component: [JDialog]->enterprisePicker1
Cannot create instance of org.statec.ide.ui.components.EnterprisePicker.
The component cannot be loaded.
И для справки:
malbert@dredg:~/.netbeans/7.0/var/log$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Server VM (build 20.1-b02, mixed mode)
malbert@dredg:~/.netbeans/7.0/var/log$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.04
DISTRIB_CODENAME=natty
DISTRIB_DESCRIPTION="Ubuntu 11.04"