Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » SWT invalid thread access exception makes eclipse crash
SWT invalid thread access exception makes eclipse crash [message #904324] Tue, 28 August 2012 08:42 Go to next message
Maxime Jeanmart is currently offline Maxime JeanmartFriend
Messages: 35
Registered: November 2010
Hi all,

I have an SWT Invalid Thread access exception at eclipse startup when I use the clean start option. This exception prevents eclipse to start because it happens during workbench initialization.

After some analysis, this exception is thrown because the WindowBuilder activator is called from a JDT builder job, which is not the main thread, and before the workbench is started. The activator (DesignerPlugin) calls Display.getDefault and makes the JDT builder thread the SWT UI thread. Unfortunately, the workbench requires the main thread to be the UI thread so eclipse crashes some time later.

To summarize, eclipse crashes because:
- The clean option makes eclipse startup slow
- The JDT builder calls the WindowBuilder activator before the workbench is initialized (or at least before the main thread is defined as UI thread)
- The WindowBuilder activator calls Display.getDefault from a Thread that is not the main thread
- The workbench requires the main thread to be the UI tread

Remark: I'm using indigo 3.7.1

Does anybody how to get around this issue? Our customer is used to start eclipse with clean option so it's a problem for him if we don't find a solution. Any idea is welcome.


Here is the stack trace:
                at org.eclipse.swt.widgets.Display.getDefault(
                at org.eclipse.wb.internal.core.DesignerPlugin.addMouseWheelRedirector(
                at org.eclipse.wb.internal.core.DesignerPlugin.start(
                at org.eclipse.osgi.framework.internal.core.BundleContextImpl$
                at Method)
                at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(
                at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(
                at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(
                at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(
                at org.eclipse.osgi.framework.util.SecureAction.start(
                at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(
                at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(
                at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(
                at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(
                at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(
                at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(
                at org.eclipse.osgi.internal.loader.BundleLoader.findClass(
                at org.eclipse.osgi.internal.loader.BundleLoader.findClass(
                at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(
                at java.lang.ClassLoader.loadClass(Unknown Source)
                at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(
                at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(
                at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(
                at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(
                at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(
                at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(
                at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(
                at org.eclipse.core.internal.content.ContentType.getDescriber(
              at org.eclipse.core.internal.content.ContentTypeCatalog.collectMatchingByContents(
                at org.eclipse.core.internal.content.ContentTypeCatalog.internalFindContentTypesFor(
                at org.eclipse.core.internal.content.ContentTypeCatalog.internalFindContentTypesFor(
                at org.eclipse.core.internal.content.ContentTypeCatalog.getDescriptionFor(
                at org.eclipse.core.internal.content.ContentTypeCatalog.getDescriptionFor(
                at org.eclipse.core.internal.content.ContentTypeMatcher.getDescriptionFor(
                at org.eclipse.core.internal.resources.ContentDescriptionManager.readDescription(
                at org.eclipse.core.internal.resources.ContentDescriptionManager.getDescriptionFor(
                at org.eclipse.core.internal.resources.File.internalGetCharset(
                at org.eclipse.core.internal.resources.File.getCharset(
                at org.eclipse.core.internal.resources.File.getCharset(
                at org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray(
                at org.eclipse.jdt.internal.core.builder.SourceFile.getContents(
                at org.eclipse.jdt.internal.compiler.parser.Parser.parse(
                at org.eclipse.jdt.internal.compiler.parser.Parser.parse(
                at org.eclipse.jdt.internal.compiler.parser.Parser.dietParse(
                at org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(
                at org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(
                at org.eclipse.jdt.internal.compiler.Compiler.compile(
                at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(
                at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(
                at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(
                at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(

Re: SWT invalid thread access exception makes eclipse crash [message #904451 is a reply to message #904324] Tue, 28 August 2012 12:53 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
In theory Display.getDefault() can be called from any thread, not only from UI thread.
This is for what it exists - to allow to run asyncExec().

It seems however that some other thread already owns Display, or some lock inside of Display.
So, WindowBuilder can not access Display.

Fixed in trunk.
Now we use Display not in DesignerPlugin.start(), but in constructor of DesignEditor, where we run in UI thread and can access Display.

Konstantin Scheglov,
Google, Inc.
Re: SWT invalid thread access exception makes eclipse crash [message #904473 is a reply to message #904451] Tue, 28 August 2012 13:40 Go to previous message
Maxime Jeanmart is currently offline Maxime JeanmartFriend
Messages: 35
Registered: November 2010
Hi Konstantin and thanks for your quick reaction. I'm not sure it's quite the same problem here. Indeed, Display.getDefault can be called from any thread. However, the first thread to call that API wins the prize and becomes the UI thread.
In this particular example, the DesignerPlugin start method is called from a JDT job thread and is the first to call Display.getDefault. Thus the job thread becomes the UI thread. Then, afterwards, the workbench fails to initialize because it assumes that the main thread is the UI thread.
Previous Topic:JavaBean Class not detected
Next Topic:why palette view is gone after re-import
Goto Forum:

Current Time: Sat Apr 21 02:26:22 GMT 2018

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

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