Community
Participate
Working Groups
As part of the work with Memory Analyzer Tool and Rich Ajax Platform and bug 323903 I tried finding assumptions about the display in our code by creating a dummy display at the start of launching MAT. public Object start(IApplicationContext context) throws Exception { Thread t = new Thread("Test") { public void run() { Display display0 = PlatformUI.createDisplay(); // break things? System.out.println("display0 = "+display0); Shell s = new Shell(display0); s.open(); try { Thread.sleep(1000000000L); } catch (InterruptedException e) { } } }; boolean f = true; if (f) { t.start(); try { Thread.sleep(1000L); } catch (InterruptedException e) { } } Display display = PlatformUI.createDisplay(); if (f) System.out.println("display1 = "+display); try { int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) return IApplication.EXIT_RESTART; return IApplication.EXIT_OK; } finally { display.dispose(); } } Our code works in this environment, but I get errors from BIRT: org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Invalid thread access) at org.eclipse.swt.SWT.error(SWT.java:4083) at org.eclipse.swt.SWT.error(SWT.java:3998) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:137) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4041) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3660) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427) at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.mat.ui.rcp.Application.start(Application.java:52) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:600) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574) at org.eclipse.equinox.launcher.Main.run(Main.java:1407) at org.eclipse.equinox.launcher.Main.main(Main.java:1383) Caused by: org.eclipse.swt.SWTException: Invalid thread access at org.eclipse.swt.SWT.error(SWT.java:4083) at org.eclipse.swt.SWT.error(SWT.java:3998) at org.eclipse.swt.SWT.error(SWT.java:3969) at org.eclipse.swt.widgets.Display.error(Display.java:1249) at org.eclipse.swt.widgets.Display.checkDevice(Display.java:736) at org.eclipse.swt.widgets.Display.getSystemFont(Display.java:2412) at org.eclipse.swt.widgets.Display.internal_new_GC(Display.java:2598) at org.eclipse.swt.graphics.GC.<init>(GC.java:166) at org.eclipse.swt.graphics.GC.<init>(GC.java:132) at org.eclipse.birt.chart.device.swt.SwtEventHandler.<init>(SwtEventHandler.java:123) at org.eclipse.birt.chart.device.swt.SwtRendererImpl.setProperty(SwtRendererImpl.java:1914) at org.eclipse.mat.ui.internal.chart.PieChartPane.createPartControl(PieChartPane.java:104) at org.eclipse.mat.ui.snapshot.panes.OverviewPane$3$1.run(OverviewPane.java:407) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134) ... 23 more I think these occur because of calls in SwtEventHandler to Display.getDefault( ) Should BIRT be presuming to use the default display? http://wiki.eclipse.org/FAQ_How_do_I_get_a_Display_instance%3F Would getting the display from the composite be better?
R31Enhance has a problem too in this environment. We could try using the current display if available, and if not then use the default. Similarly for SwtDisplayServer, though this isn't actually a problem for MAT. In SWT, Clipboard, Shell, TaskBar, Tracker and Tray have logic to use the current or failing that the default display, so it is a common idiom.