Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » PlatformUI.createAndRunWorkbench(..) does not return in JUnit plug-in tests(Although the workbench is created and closed at that point...)
icon5.gif  PlatformUI.createAndRunWorkbench(..) does not return in JUnit plug-in tests [message #997771] Tue, 08 January 2013 17:56
Kivanc Muslu is currently offline Kivanc MusluFriend
Messages: 153
Registered: November 2010
Senior Member
Hi all,

In my IApplication, I am trying to set-up an invisible workbench (e.g., just initialize the workbench and immediately close so that ui libraries that does not need to be executed by the UI thread can be used later on --- in other words, ui plug-ins are pre-loaded), with the following code:

public class SolsticeClientApplication implements IApplication
    // Suppressed due to missing library annotation.
    public Object start(@SuppressWarnings("null") IApplicationContext context) throws Exception
        int okStatus = IApplication.EXIT_OK;

        // It turns out that we have to create the display and the workbench on the main thread of
        // the headless application. It makes sense for the display as the main thread needs to
        // become the UI thread, however for the workbench, if we create an run it in another
        // thread, it just fails without any warning at all.
        final Display display = PlatformUI.createDisplay();
        int retCode = PlatformUI.createAndRunWorkbench(display, new HeadlessAdvisor());

        // Signal that the workbench is created.

        // TODO According to above comment, we are blocking the UI thread until the application
        // is over. Is that alright?
        // I guess this is fine as we are not really using the UI thread in the client
        // application. In any case we should not be invoking any code that uses the UI thread.
        // Rather, we are only using data structures and methods that are in ui packages due to the
        // way they are created, but have nothing to do with the UI thread.
        synchronized (SolsticeClient.getInstance())
        return okStatus;

    public void stop()

where HeadlessAdvisor is implemented as:

public class HeadlessAdvisor extends WorkbenchAdvisor
    public HeadlessAdvisor()

    public @Nullable
    String getInitialWindowPerspectiveId()
        return null;

    // It turns out that we have to override this method, as it normally does a lot of work in the
    // actual implementation (WorkbenchAdsivor). It would create a full-fledged workbench and then
    // return some boolean representing whether the workbench creation was successful or not.
    // However, in our case, returning 'true' just represents that for our purposes the workbench
    // creation was successful, and we don't create anything.
    public boolean openWindows()
        return true;

    public void postStartup()
        // close(..) is the call that actually closes the workbench.
            // The following method throws an exception (NullPointer?) in the internal Eclipse code:
            // Workbench:1121 ((IpresentationEngine) engine.stop();) For all our purposes, this
            // exception seems completely harmless as long as it is caught (the workbench still gets
            // closed). I think that this is due to the fact that we are not actually using any
            // workbench elements rather just trying to load the related plug-ins (for later
            // access).
        catch (Exception e)
            // Log the exception.

    public void postShutdown()
        // This method is called by close(..)

When I execute this IApplication, I get the following exception (as also explained in the code as comments above):

	at org.eclipse.ui.internal.Workbench.busyClose(
	at org.eclipse.ui.internal.Workbench.access$16(
	at org.eclipse.ui.internal.Workbench$
	at org.eclipse.swt.custom.BusyIndicator.showWhile(
	at org.eclipse.ui.internal.Workbench.close(
	at org.eclipse.ui.internal.Workbench.close(
	at com.kivancmuslu.www.solstice.client.HeadlessAdvisor.postStartup(
	at org.eclipse.ui.internal.Workbench.runUI(
	at org.eclipse.ui.internal.Workbench.access$7(
	at org.eclipse.ui.internal.Workbench$
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(
	at com.kivancmuslu.www.solstice.client.SolsticeClientApplication.start(
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.eclipse.equinox.launcher.Main.invokeFramework(
	at org.eclipse.equinox.launcher.Main.basicRun(

As I get this error (logged by the catch(..) block above), I believe at this moment IWorkbench.close(..) completed running (although by throwing an exception). In my execution logs, I see that postShutdown(..) method is called back, so my belief that the workbench is closed increases even more. Finally, if I run the same application as an Eclipse IDE application (instead of JUnit plug-in test) for manual testing, the above code (PlatformUI.createAndRunWorkbench(..)) executes and completes with success and my program works just fine (although I receive almost the same exception).

Any idea why would PlatformUI.createAndRunWorkbench(..) get stuck? Can it be something dependent on the JUnit plug-in tests (as the normal execution works fine)? Any ideas on how to fix it? Any insight on the problem is greatly appreciated.

Let me know if you need any more information about the program, code, etc. My apologies if this is the wrong forum to post, please feel free to move it to the better suited forum. Thanks in advance.

Kindest regards,
Previous Topic:Why is a return type erased
Next Topic:No indication of error/warning with annotated element on annotation processing
Goto Forum:

Current Time: Thu May 24 00:47:33 GMT 2018

Powered by FUDForum. Page generated in 0.01637 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top