United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6523638 NPE in BasicTableHeaderUI it incorrectly assumes presence of JTable
JDK-6523638 : NPE in BasicTableHeaderUI it incorrectly assumes presence of JTable

Details
Type:
Bug
Submit Date:
2007-02-09
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:
Duplicate:
Relates:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
The new row sorting mechanism for JTable in java 1.6 added code to BasicTableHeaderUI$MouseInputHandler.mouseClicked that assumes the JTableHeader has a link to an JTable.

I have a special case where a table header is rendered without an associated JTable (permitted by the JTableHeader API). Clicking on the table header produces the following exception.

This doesn't happen in Java 1.5

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Add a table header with no associated JTable to a visible UI and click on the table header.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
nothing
ACTUAL -
NullPointerException

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at javax.swing.plaf.basic.BasicTableHeaderUI$MouseInputHandler.mouseClicked(BasicTableHeaderUI.java:87)
	at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
	at java.awt.Component.processMouseEvent(Component.java:6041)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
	at java.awt.Component.processEvent(Component.java:5803)
	at java.awt.Container.processEvent(Container.java:2058)
	at java.awt.Component.dispatchEventImpl(Component.java:4410)
	at java.awt.Container.dispatchEventImpl(Container.java:2116)
	at java.awt.Component.dispatchEvent(Component.java:4240)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
    this.getContentPane().setLayout( new BorderLayout() );
    this.setSize( new Dimension(400, 300) );
    
    JTableHeader th = new JTableHeader();
    DefaultTableColumnModel dtcm = new DefaultTableColumnModel();
    dtcm.addColumn(new TableColumn(0, 100));
    th.setColumnModel(dtcm);
    th.setPreferredSize(new Dimension(100, 20));
    this.getContentPane().add(th);4240)

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Add an unused JTable to the JTableHeader with:
jtableHeader.setJTable(new JTable);

                                    

Comments
EVALUATION

The code in mouseClicked is specifically for sorting the associated table. Therefore, if there is no associated table, it should do nothing. A null check is sufficient.
                                     
2007-02-12
EVALUATION

This bug is actually a part of the 6777378, 
which main goal is to make tableHeader _must_ work as a stand-alone component
                                     
2009-03-10



Hardware and Software, Engineered to Work Together