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

JTable sorted tablechanged ArrayIndexOutOfBoundsException for clearSelectionAndL

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Incomplete
    • Affects Version/s: 8u60
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      Microsoft Windows [Version 6.1.7601]
      Copyright (c) 2009 Microsoft Corporation. All rights reserved.

      C:\Users\cservis>java -version
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode)

      C:\Users\cservis>

      ADDITIONAL OS VERSION INFORMATION :
      OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"

      A DESCRIPTION OF THE PROBLEM :
      1. Fill sortable jTable with results
      2. Select a row from the table
      3. Clear the table

      REGRESSION. Last worked in version 6u45

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Add rows to jTable
      2. select a row
      3. clear table
      4. fireTableDataChanged(); method

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      rows would be removed from jTable
      ACTUAL -
      Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
      at javax.swing.DefaultRowSorter.convertRowIndexToModel(DefaultRowSorter.java:518)
      at javax.swing.JTable.convertRowIndexToModel(JTable.java:2642)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel$TaxExemptTableModel.getRecord(TaxExemptCertificatePanel.java:750)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel$TaxExemptTableModel.access$1000(TaxExemptCertificatePanel.java:723)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel.isGoodStatus(TaxExemptCertificatePanel.java:201)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel.isRowSelectable(TaxExemptCertificatePanel.java:283)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel.access$200(TaxExemptCertificatePanel.java:29)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel$1.valueChanged(TaxExemptCertificatePanel.java:104)
      at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
      at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:154)
      at javax.swing.DefaultListSelectionModel.setValueIsAdjusting(DefaultListSelectionModel.java:685)
      at javax.swing.JTable.clearSelectionAndLeadAnchor(JTable.java:2132)
      at javax.swing.JTable.sortedTableChanged(JTable.java:4147)
      at javax.swing.JTable.tableChanged(JTable.java:4395)
      at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:296)
      at javax.swing.table.AbstractTableModel.fireTableDataChanged(AbstractTableModel.java:198)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel$TaxExemptTableModel.clearData(TaxExemptCertificatePanel.java:743)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel$TaxExemptTableModel.access$1700(TaxExemptCertificatePanel.java:723)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel.clearData(TaxExemptCertificatePanel.java:698)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel.addNewCert(TaxExemptCertificatePanel.java:296)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel.access$900(TaxExemptCertificatePanel.java:29)
      at com.discounttire.genisis.invoicesales.gui.TaxExemptCertificatePanel$8.actionPerformed(TaxExemptCertificatePanel.java:164)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
      at com.dte.widgets.gui.DTCButtonModel.setPressed(DTCButtonModel.java:49)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
      at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
      at java.awt.Component.processMouseEvent(Component.java:6525)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
      at java.awt.Component.processEvent(Component.java:6290)
      at java.awt.Container.processEvent(Container.java:2234)
      at java.awt.Component.dispatchEventImpl(Component.java:4881)
      at java.awt.Container.dispatchEventImpl(Container.java:2292)
      at java.awt.Component.dispatchEvent(Component.java:4703)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
      at java.awt.Container.dispatchEventImpl(Container.java:2278)
      at java.awt.Window.dispatchEventImpl(Window.java:2750)
      at java.awt.Component.dispatchEvent(Component.java:4703)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751)
      at java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.awt.EventQueue$3.run(EventQueue.java:702)
      at java.awt.EventQueue$3.run(EventQueue.java:696)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
      at java.awt.EventQueue$4.run(EventQueue.java:724)
      at java.awt.EventQueue$4.run(EventQueue.java:722)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:721)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:109)
      at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:184)
      at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:229)
      at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:227)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:227)
      at java.awt.Dialog.show(Dialog.java:1084)
      at java.awt.Component.show(Component.java:1654)
      at java.awt.Component.setVisible(Component.java:1606)
      at java.awt.Window.setVisible(Window.java:1014)
      at java.awt.Dialog.setVisible(Dialog.java:1005)
      at com.discounttire.genisis.invoicesales.gui.CustomerInquiryPanel$6.run(CustomerInquiryPanel.java:2986)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749)
      at java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.awt.EventQueue$3.run(EventQueue.java:702)
      at java.awt.EventQueue$3.run(EventQueue.java:696)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:719)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      private void setData(List<TaxExemptCertificate> data) {
      // a TaxExemptTableModel
              tableModel.setData(data);
      }

      private void clearData() {
              ((TaxExemptTableModel) tableModel).clearData();
      //resultsTable is a javax.swing.JTable
              resultsTable.repaint();

          }

      /**
           * A custom table model to hold TaxExemptRecord(s)
           */
          private class TaxExemptTableModel extends AbstractTableModel {

              private Object[] columns = new Object[]{"Status", "Reviewed", "State", "Reason", "Expiration"};
              private int[] columnWidth = new int[]{75, 90, 60, 90, 90};
              private List<TaxExemptCertificate> dataList = new ArrayList<TaxExemptCertificate>();

              public TaxExemptTableModel() {
                  super();

              }

              private void setData(List<TaxExemptCertificate> data) {
                  dataList.addAll(data);
                  fireTableDataChanged();
                  LOGGER.debug("setting data " + dataList.size());
              }

              private void clearData() {

                  dataList.clear();
                  fireTableDataChanged();

              }

              private TaxExemptCertificate getRecord(int row) {

                  //columns are sortable. make sure we get intended data.
                  int modelRow = resultsTable.convertRowIndexToModel(row);
                  return dataList.get(modelRow);

              }

              private int getRowIndex(int row) {
                  //CRS 11R1 01/31/2011 QC1996
                  //columns are sortable. make sure we get intended data.
                  int modelRow = resultsTable.convertRowIndexToModel(row);
                  return modelRow;

              }

              private String getCetificateReferenceID(int row) {
                  return getRecord(row).getCertificateID();
              }

              @Override
              public Object getValueAt(int row, int column) {

                  TaxExemptCertificate rec = dataList.get(row);

                  Object returnVal = "val";

                  switch (column) {
                      case 0:
                          returnVal = rec.getApplicationStatus().toString();

                          break;
                      case 1:
                          returnVal = rec.getReviewStatus().toString();

                          break;
                      case 2:
                          returnVal = rec.getStateProvince();

                          break;
                      case 3:
                          returnVal = rec.getExemptReason();

                          break;
                      case 4:

                          String expDate = rec.getExpirationDate() == null ? " " : rec.getExpirationDate().trim();
                          if (expDate.length() >= 10) {
                              returnVal = expDate.substring(0, 10);

                          } else {
                              returnVal = expDate;

                          }

                          break;
                      //CRS 11R1 SS1130
                      //case 5:
                      //if (rec.getPermitNumbers() == null || rec.getPermitNumbers().trim().isEmpty()) {
                      // returnVal = "None,";
                      // } else {
                      // returnVal = rec.getPermitNumbers();
                      // }

                      // break;
                  }
                  return returnVal;
              }

              /*
               * JTable uses this method to determine the default renderer/
               * editor for each cell. If we didn't implement this method,
               * then the last column would contain text ("true"/"false"),
               * rather than a check box.
               */
              @Override
              public Class getColumnClass(int c) {
                  //CRS 11R1 SS1130
                  //if (c == PERMITS_COL) {
                  //return JComboBox.class;
                  //} else {
                  return String.class;
                  //}

              }

              @Override
              public boolean isCellEditable(int rowIndex, int columnIndex) {
                  if (columnIndex == 5) {
                      return true;
                  }
                  return super.isCellEditable(rowIndex, columnIndex);
              }

              @Override
              public String getColumnName(int column) {
                  return columns[column].toString();
              }

              @Override
              public int getRowCount() {
                  return dataList.size();
              }

              @Override
              public int getColumnCount() {
                  return columns.length;
              }
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
       private void clearData() {
                  try {
                      dataList.clear();
                      fireTableDataChanged();
                  } catch (ArrayIndexOutOfBoundsException ae) {
                      LOGGER.debug("squash java 8 bug)");
                  }
              }

        Attachments

          Activity

            People

            Assignee:
            ssadetsky Semyon Sadetsky (Inactive)
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: