JDK-6776669 : NPE in stand-alone JTableHeader
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2008-11-26
  • Updated: 2022-02-22
  • Resolved: 2022-02-22
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
not important

A DESCRIPTION OF THE PROBLEM :
see doc in example.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
see doc in example.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
working without NPE

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/*
 * Created on 25.07.2008
 *
 */
package org.jdesktop.swingx.table;

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.table.JTableHeader;

/**
 * NPE if header not attached to a table. Basic issue is that there are various
 * code places where the access to the header's table is not guarded against null.
 * Not only in Vista context (f.i. #6668281 which is incorrectly marked as fixed) but
 * in BasicHeaderUI as well.
 *
 * To reproduce two:
 * - move a column by mouse drag to a different position
 * - double click on a column
 *
 * Beware: there are other places in the ui delegates! You need to comb thoroughly through
 * all calls to header.getTable() and make sure to guard against null before calling
 * any of table's methods.
 *
 */
public class TableHeaderNPE {

  public TableHeaderNPE() {

        try {
            UIManager.setLookAndFeel(UIManager
                    .getCrossPlatformLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        // this table is used only to quickly create a column model
        JTable table = new JTable(10, 5);
        // instantiate a tableHeader without attaching to a table
        JTableHeader header = new JTableHeader(table.getColumnModel());
        JFrame frame = new JFrame("standalone header");
        frame.add(header);
        frame.pack();
        frame.setVisible(true);
    }


    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new TableHeaderNPE();
            }
        });
    }
}
---------- END SOURCE ----------

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:6137)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5899)
        at java.awt.Container.processEvent(Container.java:2023)
        at java.awt.Component.dispatchEventImpl(Component.java:4501)
        at java.awt.Container.dispatchEventImpl(Container.java:2081)
        at java.awt.Component.dispatchEvent(Component.java:4331)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3974)

CUSTOMER SUBMITTED WORKAROUND :
None - must be fixed in ui-delegate. The base issue is the incorrect assumption hat header.getTable() is not null. This assumption led to chained method calls like header.getTable().someTableMethod throughout the various ui delegatesr (some look like over-zealous, pre-mature "optimization" effort like f.i. in getViewColumnIndex of XPHeaderRenderer) .

Note that this is a show-stopper - similar issues (f.i. #6668281) special to Vista have been incorrectly marked fixed.

Comments
Not reproducible in jdk 10 with windows 10. Looks like this has been fixed somewhere in between.
18-01-2018