Invalid Thread Access on EclipseContext.dispose() [message #1061926] |
Tue, 04 June 2013 14:15  |
Eclipse User |
|
|
|
So I have a situation where I do some work on a background thread. Since I use injection in there, I create an EclipseContext, populate it, do my business and then dispose it. However I'm getting an Invalid Thread Access when I do the dispose.
I use MVC a lot and I usually get this sort of error when I've forgotten to detach a UI object from listening to a back end object. But this trace doesn't seem to go through any of my usual suspects.
Does this look like a bug I should report? Or am I doing something wrong?
Exception in thread "Autorun" org.eclipse.e4.core.di.InjectionException: org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:88)
at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(
TrackableComputationExt.java:107)
at org.eclipse.e4.core.internal.contexts.EclipseContext.processScheduled(EclipseContext.java:328)
at org.eclipse.e4.core.internal.contexts.EclipseContext.set(EclipseContext.java:342)
at org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:192)
at org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:160)
at com.ibm.openpages.config.ui.logic.ActionExecutionLauncher.run(UnknownSource)
at com.ibm.openpages.config.admin.ui.top.TopologyRichDisplay.doRunBG(Unknown Source)
at com.ibm.openpages.config.admin.ui.top.TopologyRichDisplay$6.run(Unknown Source)
Caused by: org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:4361)
at org.eclipse.swt.SWT.error(SWT.java:4276)
at org.eclipse.swt.SWT.error(SWT.java:4247)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:359)
at org.eclipse.swt.widgets.Widget.setData(Widget.java:1220)
at org.eclipse.e4.ui.css.swt.dom.WidgetElement.setCSSClass(WidgetElement.java:65)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$11.setClassnameAndId(PartRenderingEngine.java:1248)
at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.setCSSInfo(SWTPartRenderer.java:85)
at org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer.styleStack(WBWRenderer.java:176)
at org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer.trackActivePart(WBWRenderer.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:599)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
... 9 more
|
|
|
|
|
|
Re: Invalid Thread Access on EclipseContext.dispose() [message #1062225 is a reply to message #1062150] |
Thu, 06 June 2013 10:55   |
Eclipse User |
|
|
|
I'm not quite sure what you mean by "mingle". I'll explain in more detail below.
However, if your suggestion was right, that I had a @PreDestroy that did some SWT manipulations, I would expect to see that class's code in the Invalid Thread Exception callstack. All I see on that call stack are Eclipse internals. Thus my question: is this an Eclipse bug?
Overall things look like this:
There's a class, ActionExecutionLauncher, which is a helper class for launching a unit of business logic (what we call an action, no relation to Eclipse actions). The visualization used for the running logic is determined by a parameter (and may be none at all).
So, everything starts when a static function is called on this class. It gets passed how to access the business logic, the method to visualize it, and some other stuff, and an IEclipseContext.
The first thing the static functions does is create a new EclipseContext from the context passed in, and populates it with most of the arguments.
Then the static function makes an instance of itself using ContextInjectionFactory and the sub context it just made.
The instantiated class sets a number of internal variables via injection and a @PostConstruct method.
The static function takes the instantiated class (which implements Runnable), wraps it in a thread, and kicks it off (background). It then returns to the caller.
The instantiated class's run function does the business of invoking the business logic specified. The business logic has access to the created sub-context. It may use this to create some UI. If it does, it hands off between the background and UI threads to do so.
Ultimately, the business logic returns.
At that point we try to clean up the sub-context by calling dispose and that is where we get the Invalid Thread Access.
Hmm. So sometimes the business logic will leave up a panel with its results after it "finishes". When we create a perspective/part/dialog does e4 automatically create another sub-context? If so then *that* might have some SWT stuff in it, and when ActionExecutionLauncher disposes it's sub-context the implementation of EclipseContext (according to GrepCode) also disposes all contexts created as children. Could that be what is happening?
|
|
|
|
|
|
|
|
|
Re: Invalid Thread Access on EclipseContext.dispose() [message #1064129 is a reply to message #1064124] |
Mon, 17 June 2013 14:24   |
Eclipse User |
|
|
|
Hey Eric. That's all fair enough. But what I have difficulty with is that the exception is coming from something somewhere in the Context hierarchy that is completely outside my control. I create a context, I use it, I dispose of it. However, I get this error because out there somewhere a UI object is listening to it. Sometimes it happens, sometimes it doesn't. As a developer I don't have any way of knowing if it's going to happen or not. My fear is that at someone might write their code without putting it on the UI thread because in their testing it never hit the case where whatever mysterious force is at work, requires it to be on the UI thread. Then, out in the field, that happens and, BANG they get this exception.
If this is a knock-on effect of the way EclipseContext.dispose() is implemented, perhaps that function should put its internals on the UI thread. That would save every developer everywhere from having to implicitly know that it is dangerous to dispose of this non-UI object off the UI thread. Right now this is non-intuitive.
Just sayin...
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09781 seconds