Skip to main content

NullPointerException in AutoCompleteComboBoxEditor

No replies
tjenkner
Offline
Joined: 2006-06-26

Hello,

I get the following Exception when using an autocomplete decorated JComboBox:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.jdesktop.swingx.autocomplete.AutoCompleteComboBoxEditor.getEditorComponent(AutoCompleteComboBoxEditor.java:72)
at org.jdesktop.swingx.autocomplete.ComboBoxAdaptor.getTextComponent(ComboBoxAdaptor.java:76)
at org.jdesktop.swingx.autocomplete.AbstractAutoCompleteAdaptor.markText(AbstractAutoCompleteAdaptor.java:115)
at org.jdesktop.swingx.autocomplete.AbstractAutoCompleteAdaptor.markEntireText(AbstractAutoCompleteAdaptor.java:106)
at org.jdesktop.swingx.autocomplete.ComboBoxAdaptor.actionPerformed(ComboBoxAdaptor.java:55)
at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1197)
at javax.swing.JComboBox.contentsChanged(JComboBox.java:1268)
at de.hess.zas.console.AccountListModel.setAccounts(AccountListModel.java:83)
at de.hess.zas.console.account.EntriesPanel.setAccount(EntriesPanel.java:153)
at de.hess.zas.console.account.EntriesPanel$1.handleEvent(EntriesPanel.java:74)
at de.hess.zas.console.events.ConsoleEventBroadcaster.fireUpdateEvent(ConsoleEventBroadcaster.java:140)
at de.hess.zas.console.events.ConsoleEventBroadcaster.fireEvent(ConsoleEventBroadcaster.java:107)
at de.hess.zas.console.account.LoadAccountPanel.publishAccount(LoadAccountPanel.java:223)
at de.hess.zas.console.account.LoadAccountPanel$4.loadAccount(LoadAccountPanel.java:148)
at de.hess.zas.console.account.AccountChoiceDialog$1.mouseClicked(AccountChoiceDialog.java:114)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
at java.awt.Component.processMouseEvent(Component.java:5491)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

I do not exactly know if it is a problem of the swingx.autocomplete classes or if the problem is on my side, using these classes.

However if I add a null-check in the class AutoCompleteDecorator in line 172 everything works fine:

[...]
comboBox.addPropertyChangeListener("editor", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
// new code:
if (e.getNewValue() != null && !(e.getNewValue() instanceof AutoCompleteComboBoxEditor)) {
// old code if (!(e.getNewValue() instanceof AutoCompleteComboBoxEditor)) {
comboBox.setEditor(new AutoCompleteComboBoxEditor((ComboBoxEditor) e.getNewValue(), stringConverter));
}
}
});
[...]

What do you think about it? Is the NullPointerException a bug in swingx? If it is, is the fix that I propose ok?

so long, cheers, Tobias.