Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6776669

NPE in stand-alone JTableHeader

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 6u10
    • client-libs

      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.

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: