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

NullPointerException in BasicTableHeaderUI line 87

    XMLWordPrintable

Details

    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.

      Attachments

        Issue Links

          Activity

            People

              peterz Peter Zhelezniakov
              igor Igor Nekrestyanov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: