title: Removing JTable row when sorter is applied causes IndexOutOfBoundsException
body: <p>I have a JTable with rows of custom objects, one column of which is a time component that counts down. When the countdown reaches 0 the row is to remove itself automatically. </p>
  
  <p>I also have a filter option via textbox that the user can type into to filter the rows by their data.</p>
  
  <p>Without the sorter applied to the JTable, everything works correctly (rows removing themselves when the time counts to 0) besides filtering. Applying the sorter gives me an "java.lang.IndexOutOfBoundsException: Invalid index"</p>
  
  <p>My custom table model looks like this</p>
  
  <pre><code>public Object getValueAt(int rowIndex, int columnIndex) {
  
      CustomObject myObject = customObjects.get(rowIndex);
      if (columnIndex == MyFirstColumn) {
          return myObject.getData1();
      } else if (columnIndex == MySecondColumn) {
          return myObject.getData2();
      } else if (columnIndex == TimeRemainingColumn) {
          if (myObject.getDate() - System.currentTimeMillis() &lt;= 0) {
  
              //If I comment this out I can filter but not remove rows
              removeRow(myObject); 
  
              return 0;
          }
          else{
              fireTableDataChanged();
              return myObject.getDate() - System.currentTimeMillis();
          }  
      }
  
      return DateFormat.getDateInstance().format(new Date(myObject.getDate()));
  }
  
  
  public void removeRow(CustomObject object) {
      int row = customObjects.indexOf(object);
      customObjects.remove(object);
      fireTableRowsDeleted(row, row);
  }
  </code></pre>
  
  <p>This throws this exception</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Invalid index
  at javax.swing.DefaultRowSorter.convertRowIndexToModel(DefaultRowSorter.java:514)
  at javax.swing.JTable.convertRowIndexToModel(JTable.java:2645)
  at javax.swing.JTable.getValueAt(JTable.java:2720)
  at javax.swing.JTable.prepareRenderer(JTable.java:5718)
  at javax.swing.plaf.synth.SynthTableUI.paintCell(SynthTableUI.java:684)
  at javax.swing.plaf.synth.SynthTableUI.paintCells(SynthTableUI.java:581)
  at javax.swing.plaf.synth.SynthTableUI.paint(SynthTableUI.java:365)
  at javax.swing.plaf.synth.SynthTableUI.update(SynthTableUI.java:276)
  at javax.swing.JComponent.paintComponent(JComponent.java:778)
  at javax.swing.JComponent.paint(JComponent.java:1054)
  at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221)
  ....
  </code></pre>
  
  <p>Going to DefaultRowSorter.java it is hitting this exception</p>
  
  <pre><code>public int convertRowIndexToModel(int index) {
      if (viewToModel == null) {
          if (index &lt; 0 || index &gt;= getModelWrapper().getRowCount()) {
              throw new IndexOutOfBoundsException("Invalid index");
          }
          return index;
      }
      return viewToModel[index].modelIndex;
  }
  </code></pre>
  
  <p>Up Another level, why removing works without a sorter (sorter == null)</p>
  
  <pre><code>public int convertRowIndexToModel(int viewRowIndex) {
      RowSorter sorter = getRowSorter();
      if (sorter != null) {
          return sorter.convertRowIndexToModel(viewRowIndex);
      }
      return viewRowIndex;
  }
  </code></pre>
  
  <p>Debugging a bit firstRow and endRow are both 0 at that point (they should be?) But it seems to be attempting to sort/filter an empty list</p>
  
  <p>Heres my table code</p>
  
  <pre><code>    myModel = new CustomObjectDataModel();
  
      myTable.setModel(myModel);
      mySorter = new TableRowSorter(myModel);
  
      myTable.setRowSorter(mySorter);
      myTable.setAutoCreateRowSorter(true);
  </code></pre>
  
  <p>I've searched around and found dead links to suggesting this is a bug in Java but can't confirm.</p>