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

JTable throws NPE when JAWS is running due to null value sent to renderer

XMLWordPrintable

      Basically, when JAWS is requesting information from JTable.AccessibleJTable, getAccessibleChild(int) asks for the renderer's component and always pass null for the value. This request should never be called.

      Steps to reproduce:
      ???????????????????
      1. Run JAWS 5.00.844 with Access Bridge 1.2GA
      2. Run the following application
      3. Click on a check box

      Source Code:
      ????????????
      import java.awt.Component;

      import javax.swing.BorderFactory;
      import javax.swing.DefaultCellEditor;
      import javax.swing.JCheckBox;
      import javax.swing.JComponent;
      import javax.swing.JFrame;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import javax.swing.UIManager;
      import javax.swing.table.DefaultTableModel;
      import javax.swing.table.TableCellEditor;
      import javax.swing.table.TableCellRenderer;
      import javax.swing.table.TableModel;

      final class JTableAccessibilityBug
      {
      private JFrame frame;

      public static void main(String[] args)
      {
      JTableAccessibilityBug bug = new JTableAccessibilityBug();
      bug.start();
      }

      private TableCellEditor buildBooleanEditor()
      {
      return new DefaultCellEditor(new JCheckBox());
      }

      private TableCellRenderer buildBooleanRenderer()
      {
      return new TableCellRenderer()
      {
      public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      {
      JCheckBox checkBox = new JCheckBox();
      checkBox.setSelected(((Boolean) value).booleanValue());
      return checkBox;
      }
      };
      }

      private JComponent buildContentPane()
      {
      JTable table = new JTable(buildTableModel());
      table.getAccessibleContext();
      table.setDefaultRenderer(Boolean.class, buildBooleanRenderer());
      table.setDefaultEditor(Boolean.class, buildBooleanEditor());
      return new JScrollPane(table);
      }

      private TableModel buildTableModel()
      {
      Object[] columnNames = { "Key", "Value" };

      final Object[][] data =
      {
      { "Key1", Boolean.TRUE },
      { "Key2", Boolean.FALSE },
      { "Key3", Boolean.TRUE },
      { "Key4", Boolean.FALSE },
      };

      return new DefaultTableModel(data, columnNames)
      {
      public boolean isCellEditable(int rowIndex, int columnIndex)
      {
      return (columnIndex == 1);
      }

      public Class getColumnClass(int columnIndex)
      {
      switch (columnIndex)
      {
      case 0:
      return String.class;
      case 1:
      return Boolean.class;
      default:
      return super.getColumnClass(columnIndex);
      }
      }
      };
      }

      private void start()
      {
      try
      {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
      catch (Exception e) {}

      frame = new JFrame("Test JTable Accessibility");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.getContentPane().add(buildContentPane());
      ((JComponent) frame.getContentPane()).setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
      frame.setSize(500, 300);
      frame.setLocation(100, 100);
      frame.setVisible(true);
      }
      }


      Trace Output:
      ?????????????
      java.lang.NullPointerException
      at JTableAccessibilityBug$1.getTableCellRendererComponent(JTableAccessibilityBug.java:38)
      at javax.swing.JTable$AccessibleJTable.getAccessibleChild(JTable.java:4457)
      at javax.swing.JTable$AccessibleJTable.getAccessibleAt(JTable.java:4838)
      at javax.swing.JTable$AccessibleJTable.valueChanged(JTable.java:4359)
      at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:187)
      at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167)
      at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:214)
      at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:402)
      at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:411)
      at javax.swing.DefaultListSelectionModel.setSelectionInterval(DefaultListSelectionModel.java:435)
      at javax.swing.JTable.changeSelectionModel(JTable.java:1505)
      at javax.swing.JTable.changeSelection(JTable.java:1548)
      at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.adjustFocusAndSelection(BasicTableUI.java:522)
      at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.mousePressed(BasicTableUI.java:494)
      at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:222)
      at java.awt.Component.processMouseEvent(Component.java:5097)
      at java.awt.Component.processEvent(Component.java:4897)
      at java.awt.Container.processEvent(Container.java:1569)
      at java.awt.Component.dispatchEventImpl(Component.java:3615)
      at java.awt.Container.dispatchEventImpl(Container.java:1627)
      at java.awt.Component.dispatchEvent(Component.java:3477)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3195)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
      at java.awt.Container.dispatchEventImpl(Container.java:1613)
      at java.awt.Window.dispatchEventImpl(Window.java:1606)
      at java.awt.Component.dispatchEvent(Component.java:3477)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
      ###@###.### 2004-11-06 00:00:44 GMT

            lmonsantsunw Lynn Monsanto (Inactive)
            mmma Marvin Ma (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: