Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 316331

Summary: StatusManager has InvalidThreadAccess adding status for an error
Product: [Eclipse Project] Platform Reporter: Tod Creasey <Tod_Creasey>
Component: UIAssignee: Krzysztof Daniel <krzysztof.daniel>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: krzysztof.daniel, remy.suen
Version: 3.4.2   
Target Milestone: 3.7 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Tod Creasey CLA 2010-06-09 12:07:54 EDT
If I return an error status from a job that it not running in the UI Thread the ProgressManager will call StatusManager.getManager().handle(statusAdapter,
							StatusManager.SHOW);

This opens an error dialog but as we are not in the main Thread we get an InvalidThreadAccess.

org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(SWT.java:3777)
	at org.eclipse.swt.SWT.error(SWT.java:3695)
	at org.eclipse.swt.SWT.error(SWT.java:3666)
	at org.eclipse.swt.widgets.Display.error(Display.java:1180)
	at org.eclipse.swt.widgets.Display.checkDevice(Display.java:703)
	at org.eclipse.swt.widgets.Display.getShells(Display.java:2077)
	at org.eclipse.ui.internal.progress.ProgressManagerUtil.getModalShellExcluding(ProgressManagerUtil.java:285)
	at org.eclipse.ui.internal.progress.ProgressManagerUtil.getDefaultParent(ProgressManagerUtil.java:339)
	at org.eclipse.ui.statushandlers.WorkbenchStatusDialogManager.getParentShell(WorkbenchStatusDialogManager.java:1548)
	at org.eclipse.ui.statushandlers.WorkbenchStatusDialogManager.addStatusAdapter(WorkbenchStatusDialogManager.java:1117)
	at org.eclipse.ui.statushandlers.WorkbenchErrorHandler.handle(WorkbenchErrorHandler.java:64)
	at org.eclipse.ui.internal.WorkbenchErrorHandlerProxy.handle(WorkbenchErrorHandlerProxy.java:36)
	at org.eclipse.ui.statushandlers.StatusManager.handle(StatusManager.java:200)
	at org.eclipse.ui.internal.progress.ProgressManager$1.done(ProgressManager.java:449)
	at org.eclipse.core.internal.jobs.JobListeners$3.notify(JobListeners.java:39)
	at org.eclipse.core.internal.jobs.JobListeners.doNotify(JobListeners.java:96)
	at org.eclipse.core.internal.jobs.JobListeners.done(JobListeners.java:152)
	at org.eclipse.core.internal.jobs.JobManager.endJob(JobManager.java:562)
	at org.eclipse.core.internal.jobs.WorkerPool.endJob(WorkerPool.java:105)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:72)
Comment 1 Krzysztof Daniel CLA 2010-06-22 08:15:24 EDT
WorkbenchErrorHandler.handle:

if(Display.getCurrent() != null){
  getStatusDialogManager().addStatusAdapter(...);
}

I have created a job which returned an error and it worked fine.

I think that the code could fail only if there is more than one UI thread. Is that the case?
Comment 2 Remy Suen CLA 2010-06-22 08:23:18 EDT
(In reply to comment #1)
> I think that the code could fail only if there is more than one UI thread. Is
> that the case?

This can be possible on Windows.

Debug has helped clean up a few possible causes, see bug 250048 and bug 257537, though that should've been delivered for 3.4.2. The best way is to just use breakpoints in Display's constructor and see if we're spawning two or not.
Comment 3 Krzysztof Daniel CLA 2010-06-29 09:39:30 EDT
Tod, 
could you tell us how to reproduce the issue? This is vital for further investigation.
Comment 4 Tod Creasey CLA 2010-06-30 08:00:14 EDT
I got it by opening an error dialog in a Job, I'll see if I can come up with a standalone case.
Comment 5 Krzysztof Daniel CLA 2011-04-21 04:46:34 EDT
As it was said earlier, the code is guarded against any access from non-ui threads. The only possibility in which the situation could happen is having two UI threads. 

Since Eclipse 3.4.2, more checks has been added to ensure that the error dialog is open from the UI thread.

Two fixes mentioned by Remy also could solve this issue. Since nobody else reported similar behaviour, nor the test case was constructed, I am closing this bug as worksforme.

Feel free to reopen if I have missed anything.