JDK-4895582 : Infinite count of WINDOW_CLOSED events when dispose window owner
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P2
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-07-24
  • Updated: 2003-11-25
  • Resolved: 2003-11-25
Related Reports
Relates :  
Relates :  
Relates :  
Description

Name: apR10133			Date: 07/24/2003


The Window.dispose() method unconditionally posts WINDOW_CLOSED event,
even if the window is not displayable. If the window disposes its owner
on window closed it will cause the infinite loop of window's dispose and
WINDOW_CLOSED event. I.e. when owner is disposed it calls dispose() for
the owned window, which posts the WINDOW_CLOSED event and the owner is
disposed again...

This bug breaks the fixes for the 4859570 and 4726458.

To reproduce this bug compile and run the test case below

------------------------ test.java -----------------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class test {

       public static void main(String[] argv) {
	final JFrame f = new JFrame() {
		public void dispose() {
		    super.dispose();
		    System.out.println("Dispose owner frame!");
		}
	    };
	JWindow w = new JWindow(f);
	w.addWindowListener(new WindowAdapter() {
		public void windowClosed(WindowEvent e) {
		    System.out.println("Close window!");
		    f.dispose();
		}
	    });
	w.pack();
	w.dispose();
	try {
	    Thread.sleep(3000);
	} catch(Exception e) {
	}
	System.out.println(w.getOwner().isDisplayable());
       }
}
----------------------------------------------------------

The output of the test is

Close window!
Dispose owner frame!
Close window!
Dispose owner frame!
Close window!
Dispose owner frame!
...

======================================================================

Comments
EVALUATION WINDOW_CLOSED is need to be sent only if window was displayable before dispose Name: ssR10077 Date: 10/13/2003 We discussed this matter with bug 4387314 Dialog.dispose() should remove dialog from parent's owned-windows list. The problem is Windows.dispose() posts WINDOW_CLOSED unconditionally every time dispose is called. That time I proposed to make WINDOW_OPENED/CLOSED a complimentary pair to make it at least slightly meaningful. The result of the discussion was we can't do this due to odd bug-to-bug-compatibility. The Swing tried to hook some real work on WINDOW_CLOSED. So they want a partial fix. The event should be created only in case the window was displayable before dispose(). It doesn't contradict to javadoc as we don't describe what means the window is "closed". User can only guess what "close" is an opposite to "open". If assumed WINDOW_OPENED/CLOSED is a complimentary pair (which is not right), he can also guess "open" means the window is visible. So even after this wild interpretation WINDOW_CLOSED should be posted only if the window was visible ("open") before dispose(). As the current behavior seems erratic, we probably shouldn't advert to bug-to-bug-compatibility and fix the problem at least partially. ====================================================================== Name: ssR10077 Date: 10/13/2003 The Swing problem is they try to hook parent dispose on closing of child Window. So due to unconditional WINDOW_CLOSED they fall to infinite loop. ======================================================================There There could be people relying on WINDOW_CLOSED events, so probably it's too late to change this. Closing as will not fix as the submitter has workaround.
11-06-2004