JDK-6337518 : Null Arrow Button Throws Exception in BasicComboBoxUI
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-10-17
  • Updated: 2013-12-17
  • Resolved: 2013-06-05
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
7u40 b30Fixed 8Fixed
Description
FULL PRODUCT VERSION :
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
In the class BasicComboBoxUI in the method installComponents() will throw a NullPointerException if the createArrowButton() returns null. The installComponents() method does check if it is null before it calls the configureArrowButton(). All that is needed is the call to comboBox.add( arrowButton ); be placed inside the null check. Like this:

protected void installComponents() {
    arrowButton = createArrowButton();
//    comboBox.add( arrowButton ); //move this line from here

     if (arrowButton != null)  {
        comboBox.add( arrowButton ); // to here
        configureArrowButton();
    }

    if ( comboBox.isEditable() ) {
        addEditor();
    }

    comboBox.add( currentValuePane );
}

import javax.swing.*;
import javax.swing.plaf.basic.*;
public class Test{
  protected static class TestBasicComboBoxUI extends BasicComboBoxUI{
    protected JButton createArrowButton() {
      return null;
    }
  }
  public static void main(String[] args) {
    JComboBox combobox = new JComboBox();
    combobox.setUI(new TestBasicComboBoxUI());
  }
}


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "Thread-6" java.lang.NullPointerException
	at java.awt.Container.addImpl(Container.java:1019)
	at java.awt.Container.add(Container.java:351)
	at javax.swing.plaf.basic.BasicComboBoxUI.installComponents(BasicComboBoxUI.java:646)
	at javax.swing.plaf.basic.BasicComboBoxUI.installUI(BasicComboBoxUI.java:230)
	at javax.swing.JComponent.setUI(JComponent.java:650)
	at javax.swing.JComboBox.setUI(JComboBox.java:238)
	at mil.navy.spawar.rcp.gui.dialerboard.dialer.table.InformationTableCellEditor.createPresetTypeComboBox(InformationTableCellEditor.java:68)
	at mil.navy.spawar.rcp.gui.dialerboard.dialer.table.InformationTableCellEditor.<init>(InformationTableCellEditor.java:57)
	at mil.navy.spawar.rcp.gui.dialerboard.dialer.MultipleDialerPanel.getInformationTable(MultipleDialerPanel.java:309)
	at mil.navy.spawar.rcp.gui.dialerboard.dialer.MultipleDialerPanel.getInformationScrollPane(MultipleDialerPanel.java:333)
	at mil.navy.spawar.rcp.gui.dialerboard.dialer.MultipleDialerPanel.getDataPanel(MultipleDialerPanel.java:208)
	at mil.navy.spawar.rcp.gui.dialerboard.dialer.AbstractDialerPanel.getMainSplitPane(AbstractDialerPanel.java:145)
	at mil.navy.spawar.rcp.gui.dialerboard.dialer.AbstractDialerPanel.<init>(AbstractDialerPanel.java:81)
	at mil.navy.spawar.rcp.gui.dialerboard.dialer.MultipleDialerPanel.<init>(MultipleDialerPanel.java:59)
	at mil.navy.spawar.rcp.gui.dialerboard.DialerboardPanel.getMultipleDialerPanel(DialerboardPanel.java:130)
	at mil.navy.spawar.rcp.gui.dialerboard.DialerboardPanel$1.run(DialerboardPanel.java:86)
	at java.lang.Thread.run(Thread.java:595)


REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION The Peabody fix for this bug looks correct. We could integrate this fix into Dolphin.
03-07-2006

EVALUATION Contribution-Forum:https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=12480&forumID=1463
05-04-2006

EVALUATION Yes, this is a bug. BasicComboBoxUI.installComponents() should be fixed.
24-10-2005