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

REGRESSION: GridBagLayout throws ArrayIndexOutOfBoundsExceptions

    Details

    • Subcomponent:
    • Resolved In Build:
      b56
    • CPU:
      generic, x86
    • OS:
      generic, linux, windows_2000, windows_xp

      Description


      Name: gm110360 Date: 06/01/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

      (also valid against beta 1)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      Some GridBagLayout code that previously worked in 1.4 and earlier JDKs now throws ArrayIndexOutOfBondsExceptions. These GridBagLayouts were writting using NetBeans 3.6, so I don't think I am breaking any real bad rules.

      Attached two test cases.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the two test cases attached in source code box

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      no stack traces, frame shows with some widgets
      ACTUAL -
      stack traces. See Error Message(s) box

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      C:\temp>c:\Program Files\Java\jdk1.5.0\bin\java" -cp . BreakTigerGridBag
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
              at java.awt.GridBagLayout.GetLayoutInfo(GridBagLayout.java:1025)
              at java.awt.GridBagLayout.getLayoutInfo(GridBagLayout.java:826)
              at java.awt.GridBagLayout.ArrangeGrid(GridBagLayout.java:1439)
              at java.awt.GridBagLayout.arrangeGrid(GridBagLayout.java:1399)
              at java.awt.GridBagLayout.layoutContainer(GridBagLayout.java:722)
              at java.awt.Container.layout(Container.java:1398)
              at java.awt.Container.doLayout(Container.java:1388)
              at java.awt.Container.validateTree(Container.java:1470)
              at java.awt.Container.validateTree(Container.java:1477)
              at java.awt.Container.validateTree(Container.java:1477)
              at java.awt.Container.validateTree(Container.java:1477)
              at java.awt.Container.validateTree(Container.java:1477)
              at java.awt.Container.validate(Container.java:1445)
              at java.awt.Window.show(Window.java:506)
              at BreakTigerGridBag.main(BreakTigerGridBag.java:239)

      C:\temp>"c:\Program Files\Java\jdk1.5.0\bin\java" -cp . BreakTigerGridBag2
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
              at java.awt.GridBagLayout.GetLayoutInfo(GridBagLayout.java:1047)
              at java.awt.GridBagLayout.getLayoutInfo(GridBagLayout.java:826)
              at java.awt.GridBagLayout.ArrangeGrid(GridBagLayout.java:1439)
              at java.awt.GridBagLayout.arrangeGrid(GridBagLayout.java:1399)
              at java.awt.GridBagLayout.layoutContainer(GridBagLayout.java:722)
              at java.awt.Container.layout(Container.java:1398)
              at java.awt.Container.doLayout(Container.java:1388)
              at java.awt.Container.validateTree(Container.java:1470)
              at java.awt.Container.validateTree(Container.java:1477)
              at java.awt.Container.validateTree(Container.java:1477)
              at java.awt.Container.validateTree(Container.java:1477)
              at java.awt.Container.validateTree(Container.java:1477)
              at java.awt.Container.validate(Container.java:1445)
              at java.awt.Window.show(Window.java:506)
              at BreakTigerGridBag2.main(BreakTigerGridBag2.java:866)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      ===== BreakTigerGridBag.java =====
      import java.text.DateFormat;
      import java.util.Date;
      import java.util.TimeZone;
      import javax.swing.AbstractAction;
      import javax.swing.JComponent;
      import javax.swing.JOptionPane;
      import javax.swing.JPanel;
      import javax.swing.KeyStroke;
      import javax.swing.ListSelectionModel;
      import javax.swing.SpinnerNumberModel;

      /**
       *
       * @author danno.ferrin
       */
      public class BreakTigerGridBag extends JPanel {
          
          /** Creates new form BreakTigerGridBag */
          public BreakTigerGridBag()
          {
              initComponents();
          }
          
          private void initComponents() {
              javax.swing.ButtonGroup buttonGroup1;
              java.awt.GridBagConstraints gridBagConstraints;
              javax.swing.JPanel jPanel1;
              javax.swing.JSeparator jSeparator1;
              javax.swing.JButton jButton1;
              javax.swing.JCheckBox jCheckBox1;
              javax.swing.JCheckBox jCheckBox2;
              javax.swing.JLabel jLabel1;
              javax.swing.JLabel jLabel2;
              javax.swing.JPanel jPanel2;
              javax.swing.JPanel jPanel3;
              javax.swing.JRadioButton jRadioButton1;
              javax.swing.JRadioButton jRadioButton2;
              javax.swing.JRadioButton jRadioButton3;
              javax.swing.JScrollPane jScrollPane1;
              javax.swing.JSpinner jSpinner1;
              javax.swing.JSpinner jSpinner2;
              javax.swing.JTable jTable1;

              buttonGroup1 = new javax.swing.ButtonGroup();
              jCheckBox2 = new javax.swing.JCheckBox();
              jPanel1 = new javax.swing.JPanel();
              jRadioButton3 = new javax.swing.JRadioButton();
              jSeparator1 = new javax.swing.JSeparator();
              jCheckBox1 = new javax.swing.JCheckBox();
              jRadioButton1 = new javax.swing.JRadioButton();
              jLabel1 = new javax.swing.JLabel();
              jSpinner1 = new javax.swing.JSpinner();
              jRadioButton2 = new javax.swing.JRadioButton();
              jLabel2 = new javax.swing.JLabel();
              jSpinner2 = new javax.swing.JSpinner(new javax.swing.SpinnerNumberModel(5, 1, 99, 5));
              jPanel2 = new javax.swing.JPanel();
              jScrollPane1 = new javax.swing.JScrollPane();
              jTable1 = new javax.swing.JTable();
              jButton1 = new javax.swing.JButton();
              jPanel3 = new javax.swing.JPanel();

              setLayout(new java.awt.GridBagLayout());

              jCheckBox2.setText("jCheckBox2");
              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
              gridBagConstraints.insets = new java.awt.Insets(11, 12, 0, 0);
              gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
              add(jCheckBox2, gridBagConstraints);

              jPanel1.setLayout(new java.awt.GridBagLayout());

              jPanel1.setBorder(new javax.swing.border.TitledBorder("jPanel1"));
              jRadioButton3.setSelected(true);
              jRadioButton3.setText("jRadioButton3");
              buttonGroup1.add(jRadioButton3);
              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridx = 0;
              gridBagConstraints.gridwidth = 2;
              gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
              jPanel1.add(jRadioButton3, gridBagConstraints);

              jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridx = 2;
              gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
              gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
              gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 6);
              jPanel1.add(jSeparator1, gridBagConstraints);

              jCheckBox1.setText("jCheckBox1");
              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridx = 3;
              gridBagConstraints.gridy = 0;
              gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
              gridBagConstraints.insets = new java.awt.Insets(6, 1, 0, 0);
              gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
              gridBagConstraints.weightx = 1.0;
              jPanel1.add(jCheckBox1, gridBagConstraints);

              jRadioButton1.setText("jRadioButton1");
              buttonGroup1.add(jRadioButton1);
              jRadioButton1.addItemListener(new java.awt.event.ItemListener() {
                  public void itemStateChanged(java.awt.event.ItemEvent evt) {
                      jRadioButton1ItemStateChanged(evt);
                  }
              });

              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridx = 0;
              gridBagConstraints.gridy = 1;
              gridBagConstraints.gridwidth = 2;
              gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
              jPanel1.add(jRadioButton1, gridBagConstraints);

              jLabel1.setLabelFor(jSpinner1);
              jLabel1.setText("jLabel1");
              jLabel1.setEnabled(false);
              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridx = 0;
              gridBagConstraints.gridy = 2;
              gridBagConstraints.insets = new java.awt.Insets(0, 15, 0, 4);
              gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
              jPanel1.add(jLabel1, gridBagConstraints);

              jSpinner1.setEnabled(false);
              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridx = 1;
              gridBagConstraints.gridy = 2;
              gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
              jPanel1.add(jSpinner1, gridBagConstraints);

              jRadioButton2.setText("jRadioButton2");
              buttonGroup1.add(jRadioButton2);
              jRadioButton2.addItemListener(new java.awt.event.ItemListener() {
                  public void itemStateChanged(java.awt.event.ItemEvent evt) {
                      jRadioButton2ItemStateChanged(evt);
                  }
              });

              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridx = 0;
              gridBagConstraints.gridy = 3;
              gridBagConstraints.gridwidth = 2;
              gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
              jPanel1.add(jRadioButton2, gridBagConstraints);

              jLabel2.setLabelFor(jSpinner2);
              jLabel2.setText("jLabel2");
              jLabel2.setEnabled(false);
              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridx = 0;
              gridBagConstraints.gridy = 4;
              gridBagConstraints.insets = new java.awt.Insets(0, 15, 0, 4);
              gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
              jPanel1.add(jLabel2, gridBagConstraints);

              jSpinner2.setEnabled(false);
              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridx = 1;
              gridBagConstraints.gridy = 4;
              gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
              jPanel1.add(jSpinner2, gridBagConstraints);

              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
              gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
              gridBagConstraints.insets = new java.awt.Insets(6, 12, 6, 12);
              gridBagConstraints.weightx = 1.0;
              add(jPanel1, gridBagConstraints);

              jPanel2.setLayout(new java.awt.GridBagLayout());

              jPanel2.setBorder(new javax.swing.border.TitledBorder("JPanel2"));
              jTable1.setShowHorizontalLines(false);
              jTable1.setShowVerticalLines(false);
              jScrollPane1.setViewportView(jTable1);

              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
              gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
              gridBagConstraints.weightx = 1.0;
              gridBagConstraints.weighty = 1.0;
              jPanel2.add(jScrollPane1, gridBagConstraints);

              jButton1.setText("jButton1");
              jButton1.setAlignmentX(1.0F);
              jButton1.setRolloverEnabled(true);
              jButton1.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      jButton1ActionPerformed(evt);
                  }
              });

              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
              gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
              jPanel2.add(jButton1, gridBagConstraints);

              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
              gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
              gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
              gridBagConstraints.insets = new java.awt.Insets(2, 12, 12, 12);
              gridBagConstraints.weightx = 1.0;
              gridBagConstraints.weighty = 1.0;
              add(jPanel2, gridBagConstraints);

              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
              gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
              gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
              gridBagConstraints.weightx = 1.0;
              gridBagConstraints.weighty = 1.0;
              add(jPanel3, gridBagConstraints);

          }

          private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
          }

          private void jRadioButton2ItemStateChanged(java.awt.event.ItemEvent evt) {
          }

          private void jRadioButton1ItemStateChanged(java.awt.event.ItemEvent evt) {
          }
        
          public static void main(String[] args) {
              javax.swing.JFrame frame = new javax.swing.JFrame("BreakTigerGridbag.java");
              frame.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
              frame.getContentPane().add(new BreakTigerGridBag());
              frame.setLocation(50, 50);
              frame.setSize(400, 600);
              frame.show();
          }

       }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      don't use grid bag layout. Or re-package grid bag layout from a 1.4.x JDK and re-use it.

      Release Regression From : 1.4.2
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Incident Review ID: 275470)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dav Andrei Dmitriev (Inactive)
                Reporter:
                gmanwanisunw Girish Manwani (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: