JDK-6788484 : NPE in DefaultTableCellHeaderRenderer.getColumnSortOrder() with null table
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows,windows_vista
  • CPU: generic,x86
  • Submitted: 2008-12-23
  • Updated: 2012-10-01
  • Resolved: 2009-05-18
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
6u14 b03Fixed 7Fixed
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
Passing a null table to DefaultTableCellHeaderRenderer.getColumnSortOrder() causes a NullPointerException.  This problem was probably introduced by a fix to 6668281 that came out in 1.6.0_10.



ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
	at sun.swing.table.DefaultTableCellHeaderRenderer.getColumnSortOrder(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsTableHeaderUI$XPDefaultRenderer.getTableCellRendererComponent(Unknown Source)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;

public class Bug6668281 {

    private static void createGui() {

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        JTable table = new JTable();
        JTableHeader header = table.getTableHeader();
        TableCellRenderer headerRenderer = header.getDefaultRenderer();
        headerRenderer.getTableCellRendererComponent(null, "test", false, true, -1, 0);
        System.out.println("end...");
    }

    public static void main(String[] args) throws Exception {
        Bug6668281.createGui();
    }
}

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

CUSTOMER SUBMITTED WORKAROUND :
Two workarounds listed for 6668281 worked for me too:

Workaround #1
1. Right-click on the application shortcut.
2. Select "Property"
3. Click on "Compatibility"
4. Click on the box "Disable Visual Theme"

Workaround #2
1.  Right click on an empty part of the desktop.
2.  Select "Personalize"
3.  Click "Window Color and Appearance"
4.  If currently using Aero, then click "Open classic appearance properties" link at bottom, OTHERWISE skip to step 5.
5.  In the Color scheme list, click "Windows Classic" and then click OK.
6.  Restart your broken Java app -- the exception should now not be thrown.

Release Regression From : 6u10
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
EVALUATION Note that the provided test case throws NPE only when is run on Vista
27-02-2009

EVALUATION NPE happens in DefaultTableCellHeaderRenderer.getColumnSortOrder(JTable, int) method, it doesn't check the passed JTable instance for null and calls table.getRowSorter() Need to add a null check
27-02-2009