United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6788484 NPE in DefaultTableCellHeaderRenderer.getColumnSortOrder() with null table
6788484 : NPE in DefaultTableCellHeaderRenderer.getColumnSortOrder() with null table

Details
Type:
Bug
Submit Date:
2008-12-23
Status:
Closed
Updated Date:
2012-10-01
Project Name:
JDK
Resolved Date:
2009-05-18
Component:
client-libs
OS:
windows_vista,windows
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u10,7
Fixed Versions:
6u14

Related Reports
Backport:
Duplicate:
Relates:

Sub Tasks

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

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
                                     
2009-02-27
EVALUATION

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



Hardware and Software, Engineered to Work Together