JDK-6600661 : NullPointerException in BasicTableHeaderUI line 87
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-09-04
  • Updated: 2011-01-19
  • Resolved: 2010-05-28
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)

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

A DESCRIPTION OF THE PROBLEM :
This is an edge case, admittedly, but still....  If one creates a new JTableHeader like this:

final JTableHeader header = new JTableHeader();

...and adds it as a standalone component to a content pane, and then clicks on it with a mouse, one will trigger this bug, because no JTable has ever been set on the JTableHeader.  The documentation does not indicate that a table must be set on the header.

I thought I would use the JTableHeader alone as a simple way to create a list of columns that could be dragged around (in preparation for constructing a JTable later).  That is why when I triggered this bug I didn't have a JTable.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a new JTableHeader.
2. Add it to a JFrame or other top level component's content pane so that it is visible.
3. Observe the NPE due to there not being a JTable set.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Line 87 and following in BasicTableHeaderUI should be:

            if (table != null) {
                RowSorter sorter = table.getRowSorter();
                if (sorter != null) {
                    int columnIndex = header.columnAtPoint(e.getPoint());
                    if (columnIndex != -1) {
                        columnIndex = table.convertColumnIndexToModel(
                                            columnIndex);
                        sorter.toggleSortOrder(columnIndex);
                    }
                }
            }

REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION I think we should specify that we don't support table header without a table
31-10-2007