JDK-6523638 : NPE in BasicTableHeaderUI it incorrectly assumes presence of JTable
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-02-09
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
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 6 JDK 7
6u14Fixed 7 b10Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
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 This bug is actually a part of the 6777378, which main goal is to make tableHeader _must_ work as a stand-alone component
10-03-2009

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.
12-02-2007