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

JTable.clearSelection() leaves leadSelectionIndex as 0 instead of -1

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 6u10
    • Fix Version/s: None
    • Component/s: client-libs

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_16"
      Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
      Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux garfield 2.6.31-14-generic-pae #48-Ubuntu SMP Fri Oct 16 15:22:42 UTC 2009 i686 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      I have a JTable which is using both a RowSorter and a Filter. Under certain circumstances it is giving an exception - this happens when there is a row selected, and the underlying collection is cleared.

      I noticed that this happens when the ListSelectionModel's clearSelection method sets the maxSelectoinIndex to -1 but leaves the leadSelectionIndex as zero.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.ArrayIndexOutOfBoundsException: 0
              at javax.swing.DefaultRowSorter.convertRowIndexToView(DefaultRowSorter.java:486)
              at javax.swing.JTable.convertRowIndexToView(JTable.java:2598)
              at javax.swing.JTable$SortManager.restoreSelection(JTable.java:4042)
              at javax.swing.JTable$SortManager.processChange(JTable.java:3994)
              at javax.swing.JTable.sortedTableChanged(JTable.java:4126)
              at javax.swing.JTable.tableChanged(JTable.java:4392)
              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 net.megabyte.forms.ListMaintenancePanel.refresh(ListMaintenancePanel.java:1038)
              at net.megabyte.forms.ListMaintenancePanel.refresh(ListMaintenancePanel.java:1023)
              at almira.forms.register.SupplierRateValidityMnt.setSupplierRate(SupplierRateValidityMnt.java:100)
              at almira.forms.register.SupplierRates$2.propertyChange(SupplierRates.java:76)
              at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
              at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:347)
              at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276)
              at java.awt.Component.firePropertyChange(Component.java:8128)
              at net.megabyte.forms.BaseListMaintenanceForm.fireSelectedRowChanged(BaseListMaintenanceForm.java:610)
              at net.megabyte.forms.BaseListMaintenanceForm.onChangeRow(BaseListMaintenanceForm.java:170)
              at almira.forms.register.SupplierRateMnt.onChangeRow(SupplierRateMnt.java:275)
              at almira.forms.register.SupplierRateMnt.onChangeRow(SupplierRateMnt.java:70)
              at net.megabyte.forms.ListMaintenancePanel$3.valueChanged(ListMaintenancePanel.java:225)
              at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167)
              at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:147)
              at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:194)
              at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:388)
              at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:398)
              at javax.swing.DefaultListSelectionModel.setSelectionInterval(DefaultListSelectionModel.java:442)
              at net.megabyte.swing.Table$MBDefaultListSelectionModel.setSelectionInterval(Table.java:505)
              at javax.swing.JTable.changeSelectionModel(JTable.java:2351)
              at javax.swing.JTable.changeSelection(JTable.java:2420)
              at net.megabyte.swing.Table.changeSelection(Table.java:68)
              at javax.swing.plaf.basic.BasicTableUI$Handler.adjustSelection(BasicTableUI.java:1091)
              at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:1014)
              at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263)
              at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:262)
              at java.awt.Component.processMouseEvent(Component.java:6260)
              at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
              at java.awt.Component.processEvent(Component.java:6028)
              at java.awt.Container.processEvent(Container.java:2041)
              at java.awt.Component.dispatchEventImpl(Component.java:4630)
              at java.awt.Container.dispatchEventImpl(Container.java:2099)
              at java.awt.Component.dispatchEvent(Component.java:4460)
              at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
              at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4235)
              at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
              at java.awt.Container.dispatchEventImpl(Container.java:2085)
              at java.awt.Window.dispatchEventImpl(Window.java:2475)
              at java.awt.Component.dispatchEvent(Component.java:4460)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
              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.

      CUSTOMER SUBMITTED WORKAROUND :
      I subclassed DefaultListSelectionModel and,added:

      @Override
      public int getLeadSelectionIndex() {
          int ret = super.getLeadSelectionIndex();
          if(ret > getMaxSelectionIndex()) {
              ret = getMaxSelectionIndex();
          }
          return ret;
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                alexsch Alexandr Scherbatiy
                Reporter:
                igor Igor Nekrestyanov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: