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

ArrayIndexOutOfBoundsException when defining the data with 0 rows

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.1.4
    • Fix Version/s: 1.0.2
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      1.0.2
    • CPU:
      generic
    • OS:
      solaris_2.5.1

      Description



      If I set a JTable's data array to be n elements wide and 0 long (so it
      can still have column headers, but no data) I get an exception:
      java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
              at java.util.Vector.elementAt(Vector.java)
              at com.sun.java.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.java:331)
              at com.sun.java.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.java:368)
              at com.sun.java.swing.table.DefaultTableModel.<init>(DefaultTableModel.java:213)
              at com.sun.java.swing.JTable.<init>(JTable.java:271)
              at ZeroLengthJTableTest.<init>(ZeroLengthJTableTest.java:27)
              at ZeroLengthJTableTest.main(ZeroLengthJTableTest.java:12)

      Here is the users code for reproducing:
      import java.awt.*;
      import com.sun.java.swing.*;

      public class ZeroLengthJTableTest
      extends Frame
      {
        public static void main(String args[])
        {
          ZeroLengthJTableTest t = new ZeroLengthJTableTest();
          t.show();
        }

        public ZeroLengthJTableTest()
        {
          setTitle("Zero length data JTableTest...");
          setSize(300, 400);
          setLayout(new BorderLayout());

          String colnames[] = {"foo", "bar", "baz"};
          String data[][] = new String[0][3];

          JTable t = new JTable(data, colnames);
          add(JTable.createScrollPaneForTable(t), "Center");
        }
      }


        Attachments

          Activity

            People

            Assignee:
            erapinsunw Eric Rapin (Inactive)
            Reporter:
            cahorton Catherine Horton
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: