Bug 461311 - Workaround for crashes when the user attempts to open
the window menu on Ubuntu.

Remove the radio buttons in the Window manager in the case where displaying
them may cause Eclipse to crash. This crash occurs in Unity for users who
are not using the UBUNTU_MENUPROXY environment variable.

This is a temporary workaround that should be reverted once bug 461311
is fixed.

Change-Id: Ia974190caab8c5c3905de802ef5bb2f014432f29
Signed-off-by: Stefan Xenos <sxenos@google.com>
diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
index ec4843a..7c636d5 100644
--- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
+++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
@@ -671,7 +671,24 @@
         openPreferencesItem.setVisible(!Util.isMac());
         menu.add(openPreferencesItem);
 
-        menu.add(ContributionItemFactory.OPEN_WINDOWS.create(getWindow()));
+		// Workaround for bug 461311. Radio buttons in the main menu can cause
+		// Eclipse to crash on window managers like unity that use menu proxies.
+		String menuProxy = System.getenv("UBUNTU_MENUPROXY"); //$NON-NLS-1$
+		String desktopSession = System.getenv("DESKTOP_SESSION"); //$NON-NLS-1$
+		String os = Platform.getOS();
+		String ws = Platform.getWS();
+		// Setting this property to false disables the workaround. Omitting the
+		// property or setting it to any other value
+		// enables the workaround
+		boolean workaroundEnabled = !"false".equals(System.getProperty("eclipse.workaround.bug461311")); //$NON-NLS-1$ //$NON-NLS-2$
+
+		boolean radioButtonsMightCauseCrash = ((menuProxy == null) || !menuProxy.equals("0")) //$NON-NLS-1$
+				&& Platform.WS_GTK.equals(ws) && Platform.OS_LINUX.equals(os)
+				&& (desktopSession == null || desktopSession.equals("ubuntu")) //$NON-NLS-1$
+				&& workaroundEnabled;
+		if (!radioButtonsMightCauseCrash) {
+			menu.add(ContributionItemFactory.OPEN_WINDOWS.create(getWindow()));
+		}
         return menu;
     }