Access is allowed from event dispatch thread only.

Hey all, I've noticed in recent EAP builds I now get the following exception in the TestNG-J plugin:

Access is allowed from event dispatch thread only.
Details: Current thread: Thread[ServerConnection,6,Idea Thread Group] 24870100
Our dispatch thread:Thread[AWT-EventQueue-1,6,Idea Thread Group] 27350423
SystemEventQueueThread: Thread[AWT-EventQueue-1,6,Idea Thread Group] 27350423

java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:52)
at com.intellij.openapi.application.impl.ApplicationImpl.f(ApplicationImpl.java:18)
at com.intellij.openapi.application.impl.ApplicationImpl.assertIsDispatchThread(ApplicationImpl.java:433)
at com.intellij.openapi.application.impl.LaterInvocator.getCurrentModalEntities(LaterInvocator.java:73)
at com.intellij.openapi.application.impl.ApplicationImpl.getCurrentModalityState(ApplicationImpl.java:389)
at com.intellij.openapi.application.ModalityState.current(ModalityState.java:28)
at com.theoryinpractice.testng.model.IDEARemoteTestRunnerClient.notifyStart(IDEARemoteTestRunnerClient.java:32)
at org.testng.remote.strprotocol.AbstractRemoteTestRunnerClient.receiveMessage(AbstractRemoteTestRunnerClient.java:129)
at org.testng.remote.strprotocol.AbstractRemoteTestRunnerClient.access$500(AbstractRemoteTestRunnerClient.java:33)
at org.testng.remote.strprotocol.AbstractRemoteTestRunnerClient$ServerConnection.run(AbstractRemoteTestRunnerClient.java:196)


An example of the code in question:

protected void notifyStart(final GenericMessage genericMessage) {
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
public void run() {
for(final IRemoteSuiteListener listener : m_suiteListeners) {
listener.onInitialization(genericMessage);
}
}
}, ModalityState.current());
}

The API changed recently requiring the ModalityState parameter on invokeAndWait() so I er, just randomly added one:P Not really sure which I should use there..

Is this a bug in the EAP implementation or is it due to the ModalityState I'm using?

3 comments

Hello Mark,

No, it's not a bug. It's not allowed to get the modality state of the current
component from a non-UI thread because the current component may well change
between you take it and use it, so it would be a race condition waiting to
happen. Use ModalityState.NON_MODAL instead.

MD> Hey all, I've noticed in recent EAP builds I now get the following
MD> exception in the TestNG-J plugin:
MD>
MD> Access is allowed from event dispatch thread only.
MD> Details: Current thread: Thread[ServerConnection,6,Idea Thread
MD> Group] 24870100
MD> Our dispatch thread:Thread[AWT-EventQueue-1,6,Idea Thread Group]
MD> 27350423
MD> SystemEventQueueThread: Thread[AWT-EventQueue-1,6,Idea Thread Group]
MD> 27350423
MD> java.lang.Throwable
MD> at com.intellij.openapi.diagnostic.Logger.error(Logger.java:52)
MD> at
MD> com.intellij.openapi.application.impl.ApplicationImpl.f(ApplicationI
MD> mpl.java:18)
MD> at
MD> com.intellij.openapi.application.impl.ApplicationImpl.assertIsDispat
MD> chThread(ApplicationImpl.java:433)
MD> at
MD> com.intellij.openapi.application.impl.LaterInvocator.getCurrentModal
MD> Entities(LaterInvocator.java:73)
MD> at
MD> com.intellij.openapi.application.impl.ApplicationImpl.getCurrentModa
MD> lityState(ApplicationImpl.java:389)
MD> at
MD> com.intellij.openapi.application.ModalityState.current(ModalityState
MD> .java:28)
MD> at
MD> com.theoryinpractice.testng.model.IDEARemoteTestRunnerClient.notifyS
MD> tart(IDEARemoteTestRunnerClient.java:32)
MD> at
MD> org.testng.remote.strprotocol.AbstractRemoteTestRunnerClient.receive
MD> Message(AbstractRemoteTestRunnerClient.java:129)
MD> at
MD> org.testng.remote.strprotocol.AbstractRemoteTestRunnerClient.access$
MD> 500(AbstractRemoteTestRunnerClient.java:33)
MD> at
MD> org.testng.remote.strprotocol.AbstractRemoteTestRunnerClient$ServerC
MD> onnection.run(AbstractRemoteTestRunnerClient.java:196)
MD> An example of the code in question:
MD>
MD> protected void notifyStart(final GenericMessage genericMessage)
MD> {
MD> ApplicationManager.getApplication().invokeAndWait(new
MD> Runnable() {
MD> public void run() {
MD> for(final IRemoteSuiteListener listener :
MD> m_suiteListeners) {
MD> listener.onInitialization(genericMessage);
MD> }
MD> }
MD> }, ModalityState.current());
MD> }
MD> The API changed recently requiring the ModalityState parameter on
MD> invokeAndWait() so I er, just randomly added one:P Not really sure
MD> which I should use there..
MD>
MD> Is this a bug in the EAP implementation or is it due to the
MD> ModalityState I'm using?
MD>
--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

I notice theres a spelling error in the field - ModalityState.NON_MMODAL :)

0

Hello Mark,

MD> I notice theres a spelling error in the field -
MD> ModalityState.NON_MMODAL :)

That's fixed in 6.0.

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.