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

Bug 325185

Summary: SWT Exception: Invalid Thread Access when trying to reach the display from non-UI thread.
Product: [Eclipse Project] PDE Reporter: Bahar Sateli <bahar.sateli>
Component: API ToolsAssignee: PDE API Tools Inbox <pde-apitools-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: critical    
Priority: P3 CC: remy.suen
Version: 4.0   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Whiteboard:

Description Bahar Sateli CLA 2010-09-13 20:56:41 EDT
Build Identifier:  20100617-1415

In my plug-in I have a dialog that runs a service. The service is implemented as an instance of a Job class that does the invocation over the net. When the job is finished and I want to go back to the UI thread to open a view and show the results, I get and ITA exception:

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.Widget.error(Widget.java:466)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:404)
	at org.eclipse.swt.widgets.Control.isVisible(Control.java:3173)
	at org.eclipse.ui.internal.WorkbenchPage.internalActivate(WorkbenchPage.java:602)
	at org.eclipse.ui.internal.WorkbenchPage.activate(WorkbenchPage.java:589)
	at org.eclipse.ui.internal.WorkbenchPage.busyShowView(WorkbenchPage.java:1096)
	at org.eclipse.ui.internal.WorkbenchPage.busyShowView(WorkbenchPage.java:1066)
	at org.eclipse.ui.internal.WorkbenchPage$20.run(WorkbenchPage.java:3822)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:52)
	at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:3819)
	at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:3795)
	at info.semanticsoftware.semassist.client.eclipse.handlers.FileSelectionHandler.openViews(FileSelectionHandler.java:111)
	at info.semanticsoftware.semassist.client.eclipse.handlers.EvaluationSession$1.done(EvaluationSession.java:87)
	at org.eclipse.core.internal.jobs.JobListeners$3.notify(JobListeners.java:39)
	at org.eclipse.core.internal.jobs.JobListeners.doNotify(JobListeners.java:112)
	at org.eclipse.core.internal.jobs.JobListeners.done(JobListeners.java:152)
	at org.eclipse.core.internal.jobs.JobManager.endJob(JobManager.java:646)
	at org.eclipse.core.internal.jobs.WorkerPool.endJob(WorkerPool.java:105)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:71)


P.S I'm working on Linux OpenSuse 11.3 KDE 4.

Reproducible: Always

Steps to Reproduce:
1. Create a job instance trying to do an arbitrary task.
2. From inside the job run method or the class that invoked the job.schedule() try to do window.getActivePage().showView("THE_VIEW_ID");
** window being the active workbench window
Comment 1 Remy Suen CLA 2010-09-13 21:46:32 EDT
This is not a bug but a problem with your code.
http://www.eclipse.org/swt/faq.php

Please do not use Bugzilla for requesting assistance with the usage of Eclipse APIs, that is what the forums are for.
http://www.eclipse.org/forums/
Comment 2 Paul Webster CLA 2010-09-14 07:03:51 EDT
Use the UI thread.
PW
Comment 3 Bahar Sateli CLA 2010-09-14 18:31:07 EDT
(In reply to comment #2)
> Use the UI thread.
> PW

Thanks for the super fast replies!
The Job API documentation wasn't that clear about this issue, instead I found the solution on this page http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F