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

Failure of GroupLayout in combination of addPreferredGap and addGroup's

XMLWordPrintable

        FULL PRODUCT VERSION :
        java version " 1.7.0_09 "
        Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
        Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        nothing special

        A DESCRIPTION OF THE PROBLEM :
        Depending on the comment in the attached executable file the application crashes with an OutOfMemoryError. The specified exception which causes this error is an ArrayIndexOutOfBoundsException of the Array class.The memory is increasing to infinity until the application is unable to get more memory and therefore prints this error. Some times nothing is reported because their isn't enought memory left to print a stack trace and the application hangs.

        REGRESSION. Last worked in version 6u31

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. compile the attached source file
        2. run it under Java 7 update 9, Windows 7 64 bit
        3. application hangs after a very short time (at the task manger you can also see the used memory increasing to 1 GB - depends on the heap space)

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        GroupLayout and combination of the used gaps should also work under Java 7. Under Java 6 update 35 it compiles and executes with success.
        ACTUAL -
        The application hangs.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Exception in thread " AWT-EventQueue-0 " java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Arrays.java:2245)
        at java.util.Arrays.copyOf(Arrays.java:2219)
        at java.util.ArrayList.grow(ArrayList.java:213)
        at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:187)
        at java.util.ArrayList.add(ArrayList.java:428)
        at javax.swing.GroupLayout$SequentialGroup.insertAutopadding(GroupLayout.java:2200)
        at javax.swing.GroupLayout$SequentialGroup.insertAutopadding(GroupLayout.java:2232)
        at javax.swing.GroupLayout.insertAutopadding(GroupLayout.java:1144)
        at javax.swing.GroupLayout.prepare(GroupLayout.java:1044)
        at javax.swing.GroupLayout.layoutContainer(GroupLayout.java:910)
        at java.awt.Container.layout(Container.java:1503)
        at java.awt.Container.doLayout(Container.java:1492)
        at java.awt.Container.validateTree(Container.java:1688)
        at java.awt.Container.validateTree(Container.java:1697)
        at java.awt.Container.validateTree(Container.java:1697)
        at java.awt.Container.validateTree(Container.java:1697)
        at java.awt.Container.validate(Container.java:1623)
        at java.awt.Container.validateUnconditionally(Container.java:1660)
        at java.awt.Window.show(Window.java:1033)
        at java.awt.Component.show(Component.java:1651)
        at java.awt.Component.setVisible(Component.java:1603)
        at java.awt.Window.setVisible(Window.java:1014)
        at de.desy.mst.petra.rf.client.test.TestFailureGroupLayout_Java7$1.run(TestFailureGroupLayout_Java7.java:32)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
        at java.awt.EventQueue.access$200(EventQueue.java:103)
        at java.awt.EventQueue$3.run(EventQueue.java:682)
        at java.awt.EventQueue$3.run(EventQueue.java:680)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        /**
         * File: TestFailureGroupLayout_Java7.java
         * Date: Oct 25, 2012
         */
        import javax.swing.GroupLayout;
        import javax.swing.JFrame;
        import javax.swing.JLabel;
        import javax.swing.JPanel;
        import javax.swing.LayoutStyle;
        import javax.swing.SwingUtilities;

        /**
         * Test failure of GroupLayout under Java 7 update 9, Windows 7 64 bit.
         *
         * @author <a href= " mailto:marcus(dot)walla(at)desy(dot)de " >walla</a>
         * @version $Id$
         */
        public class TestFailureGroupLayout_Java7 extends JPanel {
        private static final long serialVersionUID = 1503070885697186910L;

        public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
        @Override public void run() {
        final JFrame gui = new JFrame();
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setContentPane(new TestFailureGroupLayout_Java7());
        gui.pack();
        gui.setVisible(true);
        }
        });
        }

        public TestFailureGroupLayout_Java7() {
        final JLabel lblUps1 = new JLabel( " Ups 1! " );
        final JLabel lblUps2 = new JLabel( " Ups 2! " );
        final JLabel lblUps3 = new JLabel( " Ups 3! " );

        final GroupLayout layout = new GroupLayout(this);
        layout.setAutoCreateContainerGaps(true);
        layout.setAutoCreateGaps(true);
        this.setLayout(layout);

        layout.setHorizontalGroup(layout.createSequentialGroup()
        // commenting out the addGroup(GroupLayout.ParallelGroup) statement it will succeed
        .addGroup(layout.createParallelGroup()
        .addGroup(layout.createSequentialGroup()

        // commenting out the addPreferredGap statement it will succeed
        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)

        .addComponent(lblUps1)
            
        // commenting out the addPreferredGap statement it will succeed
        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
        )
        .addComponent(lblUps2)
        )
        .addComponent(lblUps3)
        );
        layout.setVerticalGroup(layout.createParallelGroup()
        .addComponent(lblUps1)
        .addComponent(lblUps2)
        .addComponent(lblUps3)
        );
        }
        }
        /* end of file */
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        One possibility I found is to center a component in a group with the GroupLayout.Alignment.CENTER flag instead of surrounding the component with addPreferredGap gap values. But I think it also has something to do with the combination of added groups for sequential and parallel ones.

              ssadetsky Semyon Sadetsky (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: