JDK-5109571 : REGRESSION: JDialog.setVisible(false) not honoured
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2004-09-30
  • Updated: 2017-01-25
  • Resolved: 2014-10-24
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
Name: gm110360			Date: 09/30/2004


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


ADDITIONAL OS VERSION INFORMATION :
Linux  2.4.22-1.2199.nptl  i686 athlon i386 GNU/Linux (RedHat Fedora Core 1)

A DESCRIPTION OF THE PROBLEM :
When you show a non-modal JDialog via setVisible(true) and directly a hide via setVisible(false), the dialog is not removed from the screen.

This happens in our case when we show a progress dialog, do some work, and hide the progress dialog again. When the work is done within, say, 10 milliseconds the dialog stays on the screen.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run test program. Click on the button. Multiple dialogs are created, shown and hidden.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No dialogs should be on the screen after the test.
ACTUAL -
Some dialogs are still on the screen after the test has run.

REPRODUCIBILITY :
This bug can be reproduced often.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test extends JFrame implements ActionListener
{
   private int delay = 20;
   private int loopDelay = 50;
   private int xx;
   private int x;
   private int y;
   
   public Test()
   {
      JButton button = new JButton("Test JDialog");
      button.setActionCommand("test");
      button.addActionListener(this);

      getContentPane().add(button, BorderLayout.NORTH);
      setSize(new Dimension(400, 100));
   }

   public void actionPerformed(ActionEvent e)
   {
      if ("test".equals(e.getActionCommand()))
      {
         xx+=50;
         x = xx;
         y = 0;
         
         for (int i = 0; i < 100; i++)
         {
            System.out.println("Showing dialog with delay " + delay);
            JDialog dialog = new JDialog(this, "Test Dialog", false);
            dialog.setLocation(x, y);
            dialog.setVisible(true);

            try
            {
               Thread.sleep(delay);
            }
            catch (Exception exc) { }

            dialog.setVisible(false);

            x+=5;
            y+=5;
            delay -= 5;

            if (delay < 0)
               delay = 20;

            try
            {
               Thread.sleep(loopDelay);
            }
            catch (Exception exc) { }
         }
      }
   }

   private static void createAndShowGUI()
   {
      Test test = new Test();
      test.setVisible(true);
   }

   public static void main(String[] args)
   {
      javax.swing.SwingUtilities.invokeLater(
         new Runnable()
         {
            public void run()
            {
               createAndShowGUI();
            }
         });
   }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Delay the setVisible(false) with ~50 milliseconds.

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: 315884) 
======================================================================

Comments
Won't fix. Open a new issue if there's a problem on >= JDK 7.
24-10-2014

EVALUATION Unfortunately, the fix of 6429749 does not help much. The bug is still reproduced in some environments.
16-02-2007

EVALUATION After the fix to 6429749 I've retested this one, and with delay > 0 between setVisible(true) and setVisible(false) bug is not reproduced any more. We cannot close this bug though since zero delay should also work, however bug seems someway less significant now.
14-02-2007

WORK AROUND use delay(100) between consecutive setVisible() calls ###@###.### 2005-06-23 15:20:30 GMT
23-06-2005

EVALUATION I don't beleive there's anything Swing related here. ###@###.### 2004-09-30 This is XAWT-only problem. The test shows non-modal dialog, waits for 20 msecs and hides it. Some times dialog is still visible after that. Looks like some thread race. ###@###.### 2004-10-01 Reproducable on Linux and Solaris with XToolkit. Showing/hiding of the Dialog and the Frame behaves the same. It looks like call of XUnmapWindow occurs _before_ the window gets mapped and so is not processed ###@###.### 2005-04-25 11:30:32 GMT The attempt to fix this bug had failed. The bug should be fixed on the early stage of release development to get rid of possible negative side effects. ###@###.### 2005-06-23 15:20:30 GMT
23-06-2005

SUGGESTED FIX ------- XWindowPeer.java ------- *** /tmp/sccs.kFNCUF 2005-04-25 07:29:35.000000000 -0400 --- XWindowPeer.java 2005-04-25 07:28:01.000000000 -0400 *************** *** 708,719 **** } public void handleMapNotifyEvent(long ptr) { ! super.handleMapNotifyEvent(ptr); ! if (!isNativelyNonFocusableWindow() && firstMapped) { ! requestInitialFocus(); ! firstMapped = false; } - updateAlwaysOnTop(); } protected void requestInitialFocus() { --- 708,747 ---- } public void handleMapNotifyEvent(long ptr) { ! //Fix for 5109571: REGRESSION: JDialog.setVisible(false) not honoured ! if (visible) { ! super.handleMapNotifyEvent(ptr); ! if (!isNativelyNonFocusableWindow() && firstMapped) { ! requestInitialFocus(); ! firstMapped = false; ! } ! updateAlwaysOnTop(); ! } else { ! //The xSetVisible(false) already occured. ! //Update visibility state according to the flag ! try { ! XToolkit.awtLock(); ! XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow()); ! } finally { ! XToolkit.awtUnlock(); ! } ! } ! } ! ! public void handleUnmapNotifyEvent(long ptr) { ! //Fix for 5109571: REGRESSION: JDialog.setVisible(false) not honoured ! if (!visible) { ! super.handleUnmapNotifyEvent(ptr); ! } else { ! //The xSetVisible(true) already occured. ! //Update visibility state according to the flag ! try { ! XToolkit.awtLock(); ! XlibWrapper.XMapRaised(XToolkit.getDisplay(), getWindow()); ! } finally { ! XToolkit.awtUnlock(); ! } } } protected void requestInitialFocus() { *************** *** 862,867 **** --- 890,896 ---- } public void xSetVisible(boolean visible) { + if (log.isLoggable(Level.FINE)) log.fine("Setting visible on " + this + " to " + visible); try { XToolkit.awtLock(); this.visible = visible; ###@###.### 2005-04-25 11:30:32 GMT The fix listed above has some negative effects, see the evaluation for 6267149 for details. So marking this fix as failed. ###@###.### 2005-05-11 16:25:32 GMT
25-04-2005