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

core dump with PopupMenus in wsmuser

XMLWordPrintable

    • b02
    • sparc
    • solaris_2.5.1, solaris_2.6

        I got the following bug report. I've tested
        the code on 1.1.3 and seen the core dump. I've
        included the text of the report more or less as sent.
        This may be a duplicate of 4066485, but just in case..

        On AIX and Solaris (1.1.4 and lower), this test case will cause
        a core dump if you click in the window quickly. Because of a
        delay that's been added, this core dump will happen pretty
        soon. You should be able to get it to happen within a few
        seconds.

        The reason for this is that there is a race condition between

          sun.awt.motif.MPopupMenuPeer.show(Event evt)

        and

          sun.awt.motif.MPopupMenuPeer.dispose()

        The delay in the above test case causes a delay within
        sun.awt.motif.MPopupMenuPeer which makes the race condition
        very likely.

        show(..) is called by java.awt.PopupMenu.show(..), so it is
        called from the user's thread. Often this will be from an
        event handler.

        dispose() is called by a callback from the X event loop
        (a thread called "AWT-Motif-0"). See Popup_popdownCB(..) in
        src/unix/sun/awt_PopupMenu.c. This means it will not be
        synchronized with the Java event queue (or any other thread).


        ------ PopupTest.java

        import java.awt.*;
        import java.awt.event.MouseListener;
        import java.awt.event.MouseEvent;

        public class PopupTest extends Panel implements MouseListener
        {

          public class Item extends MenuItem
          {
            public Item(String text)
            {
              super(text);
            }

            public boolean isEnabled()
            {
              try {Thread.sleep(100);} catch (InterruptedException e) {}
              return super.isEnabled();
            }
          }

          public static void main(String argv[])
          {
            Frame fr = new Frame("PopupMenu Test");
            fr.add(new PopupTest());
            fr.setSize(300, 200);
            fr.setVisible(true);
          }

          PopupMenu popup;

          public PopupTest()
          {
            popup = new PopupMenu();
            popup.add(new Item("Soap"));
            popup.add(new Item("Sponge"));
            popup.add(new Item("Flannel"));
            popup.add(new Item("Mat"));
            popup.add(new Item("Towel"));
            add(popup);
            addMouseListener(this);
          }

          public void paint(Graphics g)
          {
            Dimension dim = getSize();
            FontMetrics fm = g.getFontMetrics();
            final String text1 = "Click furiously, and it will core dump";
            final String text2 = "on Solaris and AIX 1.1.4 and earlier";
            g.drawString(text1, (dim.width - fm.stringWidth(text1))/2,
        dim.height/2-fm.getAscent());
            g.drawString(text2, (dim.width - fm.stringWidth(text2))/2,
        dim.height/2-fm.getAscent()+fm.getHeight());
          }

          public void mouseClicked(MouseEvent e)
          {
          }

          public void mousePressed(MouseEvent e)
          {
            popup.show(this, e.getX(), e.getY());
          }

          public void mouseReleased(MouseEvent e)
          {
          }

          public void mouseEntered(MouseEvent e)
          {
          }

          public void mouseExited(MouseEvent e)
          {
          }
        }

              dmendenhsunw David Mendenhall (Inactive)
              miflemi Mick Fleming
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: