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

Method DefaultTableModel.moveRow(int,int,int) throws unexpected Exception.

XMLWordPrintable

    • 1.0.2
    • sparc
    • solaris_2.5.1
    • Not verified



      Name: aaC67449 Date: 02/25/98



      Method DefaultTableModel.moveRow(int startIndex, int endIndex, int toIndex) throws unexpected ArrayIndexOutOfBoundsException.

      Javadoc says:"
      Throws:
              ArrayIndexOutOfBoundsException - if any of the indices are out of range. Or if endIndex is less than startIndex."

      -------------------Example-----------------------------------
      import java.util.*;
      import java.awt.swing.table.*;
      public class Test {

         public static void main(String argv[]) {
         DefaultTableModel c = new DefaultTableModel();
         for(int k=0;k<5;k++)
              c.addRow(new Vector()); // add row
         c.moveRow(1,2,3);
       
           }

      }
      -------------------Output------------------------------------
      java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
              at java.awt.swing.table.DefaultTableModel.moveRow(DefaultTableModel.java:631)
              at Test.main(Test.java:9)


      Exceptions are thrown because there are two mistakes in code
      (@(#)DefaultTableModel.java 1.14 98/02/02) line 629:
       
         public void moveRow(int startIndex, int endIndex, int toIndex) {
              if ((startIndex < 0) || (startIndex >= numColumns))
      // !!!!!!!!!!!!!! ^^^^^^^^^^ must be numRows, because Rows are moved
                  throw new ArrayIndexOutOfBoundsException(startIndex);
              if ((endIndex < 0) || (endIndex >= numColumns))
      // !!!!!!!!!!!!!! ^^^^^^^^^^ must be numRows
                  throw new ArrayIndexOutOfBoundsException(endIndex);
              if (startIndex < endIndex)
      // !!!!!!!!!!!!!! ^^^ must be > (see Javadoc)
                  throw new ArrayIndexOutOfBoundsException();
                  
              if ((startIndex <= toIndex) && (toIndex <= endIndex))
                  return; // Nothing to move
       



      ======================================================================

            erapinsunw Eric Rapin (Inactive)
            aalievsunw Artem Aliev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: