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

DefaultTableModel ignores last row if not correct number of columns

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta
    • generic
    • generic



      Name: krT82822 Date: 03/02/2000


      2 March 2000, eval1127@eng -- this appears to be a variant of # 4291560.
      (see also 4265749, 4270312 )
      --------------
      java version "1.3.0rc1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
      Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

      1. Define the number of columns in DefaultTableModel. Add a data row to the
      end of DefaultTableModel's data vector with [fewer] columns than previously
      defined. Try to read one of the columns that DefaultTableModel has added
      automatically to ensure the correct number of columns.

      2. Compile sun.bug.DefTabMod
      package sun.bug;

      import javax.swing.table.DefaultTableModel;
      import java.util.Vector;
      /*
       * [author name removed due to Sun privacy policy]
       * @date 28.02.2000
       */
      public class DefTabMod {
      public DefTabMod() {
      super();
      }
      /**
       * Starts the application and demonstrates under which circumstances
      DefaultTableModel
       * fails in reading the last data row.
       */
      public static void main(java.lang.String[] args)
      {
      DefaultTableModel tm = new DefaultTableModel();

      // Create column names to define number of columns
      Vector colNames = new Vector();
      colNames.addElement( "Col0" );
      colNames.addElement( "Col1" );

      Vector data = new Vector();

      // Add a row with just one column,
      // DefaultTableModel.newRowsAdded() should add a second column with
      value null
      Vector row0 = new Vector();
      row0.addElement( "Cell 0.0" );
      data.addElement( row0 );

      Vector row1 = new Vector();
      row1.addElement( "Cell 1.0" );
      data.addElement( row1 );

      tm.setDataVector( data, colNames );

      System.out.println( "Read contents of cell (0,0)" );
      System.out.println( tm.getValueAt( 0, 0 ) );

      System.out.println( "Read contents of cell (0,1)" );
      // This call succeeds and prints "null"
      System.out.println( tm.getValueAt( 0, 1 ) );

      System.out.println( "Read contents of cell (1,1)" );
      // This call fails with an ArrayIndexOutOfBoundsException
      System.out.println( tm.getValueAt( 1, 1 ) );
      }
      }


      3.
      D:\>java sun.bug.DefTabMod
      Read contents of cell (0,0)
      Cell 0.0
      Read contents of cell (0,1)
      null
      Read contents of cell (1,1)
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
              at java.util.Vector.elementAt(Vector.java:441)
              at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java
      :659)
              at sun.bug.DefTabMod.main(DefTabMod.java:49)

      4. none
      5. none
      (Review ID: 101806)
      ======================================================================

            pmilnesunw Philip Milne (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: