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

SynthTableHeaderUI refers to possibly null parameter in cell renderer

    XMLWordPrintable

Details

    • b110
    • windows_vista

    Description

      FULL PRODUCT VERSION :
      java version " 1.7.0_25 "
      Java(TM) SE Runtime Environment (build 1.7.0_25-b16)
      Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [version 6.0.6002]
      and all other OSes

      A DESCRIPTION OF THE PROBLEM :
      I used a JTableHeader as cell renderer for simulating a RowHeader.
      This JTableHeader does not have a table linked to it as it is not necessary.
      Depending on the selected look and feel, the erro occurs or not.
      With the Windows LF, there is no problem, however, when using any look and feel based on SynthLookAndFeel the bug arises.

      This is due to an inconsistant behavior in the method
      The method SynthTableHeaderUI.HeaderRenderer.getTableCellRendererComponent
      The parameter JTable table is not checked to null before calling the method table.isEnabled() but after that, this same parameter is compared to null :

      [code]
              public Component getTableCellRendererComponent(JTable table, Object value,
                                                             boolean isSelected,
                                                             boolean hasFocus,
                                                             int row, int column) {

                  boolean hasRollover = (column == getRolloverColumn());
                  if (isSelected || hasRollover || hasFocus) {
                      SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel.
                                   getUIOfType(getUI(), SynthLabelUI.class),
                                   isSelected, hasFocus, table.isEnabled(),
                                   hasRollover);
                  } else {
                      SynthLookAndFeel.resetSelectedUI();
                  }

                  //stuff a variable into the client property of this renderer indicating the sort order,
                  //so that different rendering can be done for the header based on sorted state.
                  RowSorter rs = table == null ? null : table.getRowSorter();
                  java.util.List<? extends RowSorter.SortKey> sortKeys = rs == null ? null : rs.getSortKeys();
      ...
      [/code]

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      First of all, use the Nimbus Look and Feel.
      Create a new JTableHeader and use it without associated table and use it as a cell renderer for example.

      or simply run the sample code.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The JTableHeader with Nimbus L&F should be used without associated JTable when necessary.

      ACTUAL -
      An error is raised each time the method
      SynthTableHeaderUI.HeaderRenderer.getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      is called with a parameter table set to null.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.NullPointerException at javax.swing.plaf.synth.SynthTableHeaderUI$HeaderRenderer.getTableCellRendererComponent(SynthTableHeaderUI.java:233)

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class BugHeaderRenderer {
      public static void main(String[] args) {
      try {
      UIManager.setLookAndFeel( " javax.swing.plaf.nimbus.NimbusLookAndFeel " );
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      JTableHeader header = new JTableHeader();
      header.getDefaultRenderer().getTableCellRendererComponent(null, " test " , true, true, -1, 0);
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Associate the TableHeader to a dummy JTable like this:

      [code]
      JTableHeader header = new JTableHeader();
      JTable table = new JTable();
      table.setTableHeader(header);
      [/code]

      After that, when the getTableCellRendererComponent() is automatically called, the parameter " table " is no more null.

      Attachments

        Issue Links

          Activity

            People

              aghaisas Ajit Ghaisas
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: