From 6182eb107f0f7e5ca58c5fe6117bfd0f7ff4fc8f Mon Sep 17 00:00:00 2001 From: Pawel Piech Date: Tue, 4 Sep 2012 11:22:37 -0700 Subject: [PATCH] Bug 388238 - NPE when calling DebugUIPlugin.launchInBackground() from non-UI thread Change-Id: Id65086ab6dcc8ec2efa1e66fb5bae48154add7cc Reviewed-on: https://git.eclipse.org/r/7602 Reviewed-by: Marc Khouzam IP-Clean: Marc Khouzam Tested-by: Marc Khouzam --- .../breakpointactions/ExternalToolAction.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpointactions/ExternalToolAction.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpointactions/ExternalToolAction.java index 16a683cce03..47c68452f22 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpointactions/ExternalToolAction.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpointactions/ExternalToolAction.java @@ -12,7 +12,6 @@ package org.eclipse.cdt.debug.ui.breakpointactions; import java.io.ByteArrayOutputStream; import java.io.StringReader; -import com.ibm.icu.text.MessageFormat; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -31,22 +30,46 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.ui.progress.WorkbenchJob; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; import org.xml.sax.helpers.DefaultHandler; +import com.ibm.icu.text.MessageFormat; + public class ExternalToolAction extends AbstractBreakpointAction { private String externalToolName = ""; //$NON-NLS-1$ - @Override - public IStatus execute(IBreakpoint breakpoint, IAdaptable context, IProgressMonitor monitor) { + @Override + public IStatus execute(final IBreakpoint breakpoint, final IAdaptable context, final IProgressMonitor monitor) { + Job uiJob = new WorkbenchJob("ExternalToolAction") { //$NON-NLS-1$ + { + setPriority(INTERACTIVE); + } + + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + return executeInUIThread(breakpoint, context, monitor); + } + }; + uiJob.schedule(); + try { + uiJob.join(); + } catch (InterruptedException e) { + return Status.CANCEL_STATUS; + } + return uiJob.getResult(); + } + + private IStatus executeInUIThread(IBreakpoint breakpoint, IAdaptable context, IProgressMonitor monitor) { IStatus errorStatus = null; ILaunchManager lcm = DebugPlugin.getDefault().getLaunchManager(); try {