Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » org.eclipse.swt.SWTException: Invalid thread access in AbstractContentAssistProcessorTest
org.eclipse.swt.SWTException: Invalid thread access in AbstractContentAssistProcessorTest [message #1236864] Tue, 28 January 2014 09:05 Go to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
I'm using org.eclipse.xtext.junit4.ui.AbstractContentAssistProcessorTest to run tests for my DSL's content proposal provider.

This worked flawlessly in Xtext 2.3. Since my update to 2.4, I get org.eclipse.swt.SWTException: Invalid thread access in org.eclipse.xtext.junit4.ui.ContentAssistProcessorTestBuilder.computeCompletionProposals(ContentAssistProcessorTestBuilder.java:384):

	protected ICompletionProposal[] computeCompletionProposals(final IXtextDocument xtextDocument, int cursorPosition)
			throws BadLocationException {
		Shell shell = new Shell(); // <---- Exception happens here
		try {
			return computeCompletionProposals(xtextDocument, cursorPosition, shell);
		} finally {
			shell.dispose();
		}
	}


Any ideas how to solve this?
Re: org.eclipse.swt.SWTException: Invalid thread access in AbstractContentAssistProcessorTest [message #1236872 is a reply to message #1236864] Tue, 28 January 2014 09:13 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
For my tests, I need a Java project. I'm using JavaProjectSetupUtil to create one. This happens in a worker thread when I run the Plugin Unit Tests. When the project loads its preferences, a default Display is created which associates the worker thread with the display.

When the worker is done, my test continues. The test runs in the Main thread. This means the next access to an SWT widget will cause the ERROR_THREAD_INVALID_ACCESS.

So my first attempt to fix this was to add Display.getDefault() in the main thread. But this causes a wierd exception:

com.google.inject.ProvisionException: Guice provision errors:

1) Error injecting constructor, java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jface.preference.PreferenceConverter
  at org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider.<init>(Unknown Source)
  at org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider.class(Unknown Source)
  while locating org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider
  while locating org.eclipse.xtext.ui.editor.syntaxcoloring.ITextAttributeProvider
    for field at org.eclipse.xtext.ui.editor.syntaxcoloring.AbstractTokenScanner.textAttributeProvider(Unknown Source)
  while locating org.eclipse.xtext.ui.editor.syntaxcoloring.TokenScanner
  while locating org.eclipse.jface.text.rules.ITokenScanner
    for parameter 0 at org.eclipse.xtext.ui.editor.syntaxcoloring.PresentationRepairer.<init>(Unknown Source)
  while locating org.eclipse.xtext.ui.editor.syntaxcoloring.PresentationRepairer
  while locating org.eclipse.jface.text.presentation.IPresentationRepairer

1 error
	at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:987)
	at org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration.getPresentationReconciler(XtextSourceViewerConfiguration.java:135)
	at org.eclipse.jface.text.source.SourceViewer.configure(SourceViewer.java:456)
	at org.eclipse.xtext.junit4.ui.ContentAssistProcessorTestBuilder.getSourceViewer(ContentAssistProcessorTestBuilder.java:419)
	at org.eclipse.xtext.junit4.ui.ContentAssistProcessorTestBuilder.computeCompletionProposals(ContentAssistProcessorTestBuilder.java:395)
	at org.eclipse.xtext.junit4.ui.ContentAssistProcessorTestBuilder.computeCompletionProposals(ContentAssistProcessorTestBuilder.java:386)
	at org.eclipse.xtext.junit4.ui.ContentAssistProcessorTestBuilder.computeCompletionProposals(ContentAssistProcessorTestBuilder.java:379)
	at org.eclipse.xtext.junit4.ui.ContentAssistProcessorTestBuilder.assertTextAtCursorPosition(ContentAssistProcessorTestBuilder.java:250)
	at org.eclipse.xtext.junit4.ui.ContentAssistProcessorTestBuilder.assertText(ContentAssistProcessorTestBuilder.java:215)
	at com.pany.project.dsl.ui.contentassist.ProjectDslProposalProviderTest.testFoo(ProjectDslProposalProviderTest.java:133)
	...
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	...
	at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jface.preference.PreferenceConverter
	at org.eclipse.xtext.ui.editor.syntaxcoloring.PreferenceStoreAccessor.populateTextStyle(PreferenceStoreAccessor.java:56)
	at org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider.createTextAttribute(TextAttributeProvider.java:105)
	at org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider.acceptDefaultHighlighting(TextAttributeProvider.java:99)
	at com.pany.project.dsl.ui.labeling.ProjectDslHighlightingConfiguration.configure(ProjectDslHighlightingConfiguration.java:16)
	at org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider.initialize(TextAttributeProvider.java:48)
	at org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider.<init>(TextAttributeProvider.java:43)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at com.google.inject.internal.*
	... 55 more


Any ideas?
Re: org.eclipse.swt.SWTException: Invalid thread access in AbstractContentAssistProcessorTest [message #1236873 is a reply to message #1236864] Tue, 28 January 2014 09:10 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1763
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 28/01/2014 10:05, Aaron Digulla wrote:
> I'm using org.eclipse.xtext.junit4.ui.AbstractContentAssistProcessorTest
> to run tests for my DSL's content proposal provider.
>
> This worked flawlessly in Xtext 2.3. Since my update to 2.4, I get
> org.eclipse.swt.SWTException: Invalid thread access in
> org.eclipse.xtext.junit4.ui.ContentAssistProcessorTestBuilder.computeCompletionProposals(ContentAssistProcessorTestBuilder.java:384):
>
>
>
> protected ICompletionProposal[] computeCompletionProposals(final
> IXtextDocument xtextDocument, int cursorPosition)
> throws BadLocationException {
> Shell shell = new Shell(); // <---- Exception happens here
> try {
> return computeCompletionProposals(xtextDocument,
> cursorPosition, shell);
> } finally {
> shell.dispose();
> }
> }
>
>
> Any ideas how to solve this?

Hi

you may want to try
org.eclipse.xtext.xbase.junit.ui.AbstractContentAssistTest

(IIRC the domain model example has tests for content assist)

hope this helps
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: org.eclipse.swt.SWTException: Invalid thread access in AbstractContentAssistProcessorTest [message #1237021 is a reply to message #1236873] Tue, 28 January 2014 16:29 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Lorenzo Bettini wrote on Tue, 28 January 2014 10:10
On 28/01/2014 10:05, Aaron Digulla wrote:
you may want to try
org.eclipse.xtext.xbase.junit.ui.AbstractContentAssistTest


I'm using JUnit 4 everywhere, so I don't like to add a dependency on JUnit 3 to my plugins.

Also note that I was using that class but since the update from Xtext 2.3 to 2.4, I got strange errors.

So at the moment, I'm left with a project where content assist tests don't work Sad
Re: org.eclipse.swt.SWTException: Invalid thread access in AbstractContentAssistProcessorTest [message #1237031 is a reply to message #1237021] Tue, 28 January 2014 17:06 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1763
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 28/01/2014 17:29, Aaron Digulla wrote:
> Lorenzo Bettini wrote on Tue, 28 January 2014 10:10
>> On 28/01/2014 10:05, Aaron Digulla wrote:
>> you may want to try
>> org.eclipse.xtext.xbase.junit.ui.AbstractContentAssistTest
>
>
> I'm using JUnit 4 everywhere, so I don't like to add a dependency on
> JUnit 3 to my plugins.
>
> Also note that I was using that class but since the update from Xtext
> 2.3 to 2.4, I got strange errors.
>
> So at the moment, I'm left with a project where content assist tests
> don't work :(

Have a look at

import org.eclipse.xtext.xbase.junit.ui.AbstractContentAssistTest
class ContentAssistTest extends AbstractContentAssistTest {

in the domain model example; it is Junit 4, not 3

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: org.eclipse.swt.SWTException: Invalid thread access in AbstractContentAssistProcessorTest [message #1238129 is a reply to message #1237031] Fri, 31 January 2014 13:24 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
org.eclipse.xtext.xbase.junit.ui.AbstractContentAssistTest works slightly better. The tests now run inside of Eclipse but they fail when I run them with Maven Tycho from the command line ("Invalid thread access") Sad

Looking at the code, AbstractContentAssistTest uses org.eclipse.xtext.junit4.ui.ContentAssistProcessorTestBuilder which is the same problem as in my first post.
Re: org.eclipse.swt.SWTException: Invalid thread access in AbstractContentAssistProcessorTest [message #1238140 is a reply to message #1238129] Fri, 31 January 2014 13:58 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1763
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 31/01/2014 14:24, Aaron Digulla wrote:
> org.eclipse.xtext.xbase.junit.ui.AbstractContentAssistTest works
> slightly better. The tests now run inside of Eclipse but they fail when
> I run them with Maven Tycho from the command line ("Invalid thread
> access") :(
>
> Looking at the code, AbstractContentAssistTest uses
> org.eclipse.xtext.junit4.ui.ContentAssistProcessorTestBuilder which is
> the same problem as in my first post.

So probably they must be run in the UI Thread, and they need a running
Eclipse workbench; you may have to update your tycho surefire plugin
params, I guess...

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:Problem with "package" in my DSL
Next Topic:UML-Profile -> Xtext Grammar
Goto Forum:
  


Current Time: Thu Jul 09 20:55:32 GMT 2020

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

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

Back to the top