Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322253 - [Widgets] Context menu does not go away after setVisible(false)
Summary: [Widgets] Context menu does not go away after setVisible(false)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.7   Edit
Hardware: PC Mac OS X
: P3 major (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Lakshmi P Shanmugam CLA
QA Contact: Scott Kovatch CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-10 12:37 EDT by Dani Megert CLA
Modified: 2010-08-13 10:53 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2010-08-10 12:37:42 EDT
3.5, 3.6 and latest 3.7 build. Happens on MacOSX 10.5.6 and 10.5.8 but not 10.6.

Our org.eclipse.jdt.ui.tests.leaks.JavaLeakTest.testJavaEditorContextMenu() test ('org.eclipse.jdt.ui.tests' bundle) waits forever on Mac Cocoa because the menu doesn't get closed using setVisible(false). The result is that the test runs 2 hours before it gets killed. This works on all other platforms and also on the latest Mac version, hence filing against SWT.

The relevant code is in JavaLeakTest.openContextMenu(Menu). Should be easy to extract a snippet from that.
Comment 1 Dani Megert CLA 2010-08-10 12:46:21 EDT
IMPORTANT NOTE: We disabled the test on Cocoa for now. To reproduce you need to remove the first two lines in JavaLeakTest.testJavaEditorContextMenu().


Lakshmi, you said you have access to a Mac with 10.5.x? If so, could you try to reproduce and create a small snippet? Thanks.
Comment 2 Markus Keller CLA 2010-08-10 13:47:46 EDT
> but not 10.6.

That's probably wrong. I initially ran the whole leak test suite via VNC on Cocoa/10.6, and it passed. Now I ran only JavaLeakTest.testJavaEditorContextMenu() and made sure I didn't touch the machine, and it looked like the menu also stayed up forever.

Could be related to bug 246843. Maybe menu.setVisible(true) is also delayed here and the asyncExec that should hide the menu gets executed before the menu is even visible?
Comment 3 Markus Keller CLA 2010-08-10 14:23:08 EDT
The snippet below prints ...

menu.setVisible (true)
menuShown
menu.setVisible (false)

... and then shows the menu indefinitely on HEAD Cocoa on MacOS 10.6.4.
Replacing the asyncExec(..) with display.timerExec(1000, ..) doesn't help.


public class SnippetBug322253 {
	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.open();

		final Menu menu = new Menu(shell, SWT.POP_UP);
		menu.addMenuListener(new MenuListener() {
			public void menuShown(MenuEvent e) {
				System.out.println("menuShown");
			}
			public void menuHidden(MenuEvent e) {
				System.out.println("menuHidden");
			}
		});
		MenuItem item = new MenuItem(menu, SWT.PUSH);
		item.setText("Menu Item");

		while (!menu.isDisposed() && display.readAndDispatch()) {
			// loop, don't sleep
		}

		System.out.println("menu.setVisible (true)");
		menu.setVisible(true);
		display.asyncExec(new Runnable() {
			public void run() {
				System.out.println("menu.setVisible (false)");
				menu.setVisible(false);
			}
		});

		while (!menu.isDisposed() && display.readAndDispatch()) {
			// loop, don't sleep
		}

		display.dispose();
	}
}
Comment 4 Lakshmi P Shanmugam CLA 2010-08-11 04:27:12 EDT
(In reply to comment #1)
Hi Dani, I can reproduce this using the snippet in comment3 with both 10.5.8 and 10.6.3.
Comment 5 Lakshmi P Shanmugam CLA 2010-08-13 08:58:40 EDT
calling _setVisible(false) in Menu.setVisible fixes this. We call it in the
other platforms, not sure why we are not calling it cocoa?
Comment 6 Silenio Quarti CLA 2010-08-13 10:24:05 EDT
(In reply to comment #5)
> calling _setVisible(false) in Menu.setVisible fixes this. We call it in the
> other platforms, not sure why we are not calling it cocoa?

I am not sure either. Looking at the history does not indicate any good reason. Please make the change.
Comment 7 Lakshmi P Shanmugam CLA 2010-08-13 10:53:57 EDT
Fixed in HEAD > 20100813.