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

ArrayIndexOutOfBoundsException when clearing table model

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0_23"
      Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
      Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Multiple versions of Windows 7 and Windows XP, does not seem to be limited to particular OS.

      A DESCRIPTION OF THE PROBLEM :
      This bug is probably a duplicate to a closed bug (6921688) but I could not add my test case there.

      I have a JTable with bound table model (using org.jdesktop.beansbinding), there is a row filter in effect and the first row is selected, but filtered out. Clearing the model then throws an exception.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Both the model and selection should be cleared, no exception thrown.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
              at javax.swing.DefaultRowSorter.convertRowIndexToView(DefaultRowSorter.java:486)
              at javax.swing.JTable.convertRowIndexToView(JTable.java:2589)
              at javax.swing.JTable$SortManager.restoreSelection(JTable.java:4033)
              at javax.swing.JTable$SortManager.processChange(JTable.java:3985)
              at javax.swing.JTable.sortedTableChanged(JTable.java:4117)
              at javax.swing.JTable.tableChanged(JTable.java:4383)
              at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.fireTableModelEvent(JTableBinding.java:832)
              at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.removed(JTableBinding.java:797)
              at org.jdesktop.swingbinding.impl.ListBindingManager.listElementsRemoved(ListBindingManager.java:137)
              at org.jdesktop.observablecollections.ObservableCollections$ObservableListImpl.clear(ObservableCollections.java:328)
              at desktopapplication2.NewJFrame.<init>(NewJFrame.java:55)
              at desktopapplication2.NewJFrame$2.run(NewJFrame.java:136)
              at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
              at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      package desktopapplication2;

      import java.util.ArrayList;
      import java.util.List;
      import javax.swing.RowFilter;
      import javax.swing.table.TableRowSorter;

      public class NewJFrame extends javax.swing.JFrame {

          public static class Data {
              String a;
              String b;

              public String getA() {
                  return a;
              }

              public void setA(String a) {
                  this.a = a;
              }

              public String getB() {
                  return b;
              }

              public void setB(String b) {
                  this.b = b;
              }

              public Data(String a, String b) {
                  this.a = a;
                  this.b = b;
              }


          }

          List<Data> data;

          public List<Data> getData() {
              return data;
          }
          

          /** Creates new form NewJFrame */
          public NewJFrame() {
              data = org.jdesktop.observablecollections.ObservableCollections.observableList(new ArrayList<Data>());
              initComponents();
              data.add(new Data("aa","bb"));
              data.add(new Data("cc","dd"));
              jTable1.getSelectionModel().addSelectionInterval(0, 0);
              TableRowSorter sorter = (TableRowSorter)jTable1.getRowSorter();
              sorter.setRowFilter(RowFilter.regexFilter("c", 0));

              //Following throws an exeption.
              data.clear();
          }

          /** This method is called from within the constructor to
           * initialize the form.
           * WARNING: Do NOT modify this code. The content of this method is
           * always regenerated by the Form Editor.
           */
          @SuppressWarnings("unchecked")
          // <editor-fold defaultstate="collapsed" desc="Generated Code">
          private void initComponents() {
              bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

              jScrollPane1 = new javax.swing.JScrollPane();
              jTable1 = new javax.swing.JTable();

              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
              setName("Form"); // NOI18N

              jScrollPane1.setName("jScrollPane1"); // NOI18N

              jTable1.setAutoCreateRowSorter(true);
              jTable1.setName("jTable1"); // NOI18N

              org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${data}");
              org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, jTable1);
              org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${a}"));
              columnBinding.setColumnName("A");
              columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${b}"));
              columnBinding.setColumnName("B");
              bindingGroup.addBinding(jTableBinding);
              jTableBinding.bind();
              jScrollPane1.setViewportView(jTable1);
              org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(NewJFrame.class);
              jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addContainerGap(15, Short.MAX_VALUE))
              );
              layout.setVerticalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addContainerGap(29, Short.MAX_VALUE))
              );

              bindingGroup.bind();

              pack();
          }// </editor-fold>

          /**
          * @param args the command line arguments
          */
          public static void main(String args[]) {
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new NewJFrame().setVisible(true);
                  }
              });
          }

          // Variables declaration - do not modify
          private javax.swing.JScrollPane jScrollPane1;
          private javax.swing.JTable jTable1;
          private org.jdesktop.beansbinding.BindingGroup bindingGroup;
          // End of variables declaration

      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: