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

JDialog subclass call to dispose crashes application with core dump

XMLWordPrintable

    • b02
    • sparc
    • solaris_2.5.1, solaris_9

        The code pasted below worked under jdk1.1.5 but crashes with segmentation faults in jdk1.1.6. The JDialog ActionListeners have a call to dispose() which seems to be the problem. When I remove that call from the JDialog subclass and put it into main, I don't crash.

        I am after information on the change from 1.1.5 to 1.1.6 that will explain this behavior and whether or not it will be fixed.

        import java.awt.*;
        import java.awt.event.*;
        import java.util.*;
        import com.sun.java.swing.*;

        class Dialog1 extends JDialog {
            public Dialog1(JFrame dframe, Point center) {
                super(frame, "A dialog", true);
                JPanel panel = new JPanel();
                panel.setLayout(new BorderLayout());
                panel.add("Center", new JTextArea());
                JButton button;
                panel.add("South", button = new JButton("Dispose"));
                button.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        dispose();
                    }
                });
                panel.setPreferredSize(new Dimension(200,100));
                getContentPane().add(panel);
                pack();
                setLocation(center);
                show();
            }
        }

        class Dialog2 extends JDialog {
            public Dialog2(JFrame dframe, Point center) {
                super(frame, "Another dialog", true);
                JPanel panel = new JPanel();
                panel.setLayout(new BorderLayout());
                panel.add("North", new JTextField());
                JButton button;
                panel.add("South", button = new JButton("Dispose"));
                button.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        dispose();
                    }
                });
                panel.setPreferredSize(new Dimension(200,80));
                getContentPane().add(panel);
                pack();
                setLocation(center);
                show();
            }
        }

        public class DialogTest extends JDialog {
            public static void main(String args[]) {
        final JFrame frame = new JFrame();
        frame.setSize(200,100);

                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        final Point center = new Point(screenSize.width/2 - 50,
                                                screenSize.height/2 - 50);
                frame.setLocation(center);

        frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
        System.exit(0);
        }
        });

        JPanel container = new JPanel();
        container.setLayout(new GridLayout());
        JButton buttons[] = new JButton[10];
        int i = 0;
        buttons[i] = new JButton("Press " + i);
        container.add(buttons[i]);
        buttons[i].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        new Dialog1(frame,center);
        }
                });

        i++;
        buttons[i] = new JButton("Press " + i);
        container.add(buttons[i]);
        buttons[i].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        new Dialog2(frame,center);
        }
                });

        frame.getContentPane().add(container);
        frame.show();
            }
        }

              mbronsonsunw Mike Bronson (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: