Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Invalid Thread Access in MenuManagerRenderer.contextDisposed
Invalid Thread Access in MenuManagerRenderer.contextDisposed [message #1182436] Tue, 12 November 2013 07:25 Go to next message
Matthias Nick is currently offline Matthias Nick
Messages: 172
Registered: August 2013
Senior Member
Hi, when I close my RCP application I get an invalid thread access:

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.di.InjectorImpl.processAnnotated(InjectorImpl.java:877)
	at org.eclipse.e4.core.internal.di.InjectorImpl.disposed(InjectorImpl.java:386)
	at org.eclipse.e4.core.internal.di.Requestor.disposed(Requestor.java:132)
	at org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:76)
	at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:107)
	at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.handleInvalid(TrackableComputationExt.java:70)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:171)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:160)
	at org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.dispose(EclipseContextOSGi.java:100)
	at org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.bundleChanged(EclipseContextOSGi.java:131)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:892)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:165)
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:75)
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:67)
	at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:87)
	at org.eclipse.osgi.container.Module.publishEvent(Module.java:454)
	at org.eclipse.osgi.container.Module.doStop(Module.java:609)
	at org.eclipse.osgi.container.Module.stop(Module.java:476)
	at org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:165)
	at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:216)
	at java.lang.Thread.run(Thread.java:722)
Caused by: org.eclipse.swt.SWTException: Invalid thread access
org.eclipse.swt.SWT.error(SWT.java:4419)
org.eclipse.swt.SWT.error(SWT.java:4334)
org.eclipse.swt.SWT.error(SWT.java:4305)
org.eclipse.swt.widgets.Display.error(Display.java:1257)
org.eclipse.swt.widgets.Display.checkDevice(Display.java:763)
org.eclipse.swt.widgets.Display.removeFilter(Display.java:4062)
org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.contextDisposed(MenuManagerRenderer.java:254)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:877)
org.eclipse.e4.core.internal.di.InjectorImpl.disposed(InjectorImpl.java:386)
org.eclipse.e4.core.internal.di.Requestor.disposed(Requestor.java:132)
org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:76)
org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:107)
org.eclipse.e4.core.internal.contexts.TrackableComputationExt.handleInvalid(TrackableComputationExt.java:70)
org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:171)
org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:160)
org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.dispose(EclipseContextOSGi.java:100)
org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.bundleChanged(EclipseContextOSGi.java:131)
org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:902)
org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:165)
org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:75)
org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:67)
org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:89)
org.eclipse.osgi.container.Module.publishEvent(Module.java:456)
org.eclipse.osgi.container.Module.doStop(Module.java:611)
org.eclipse.osgi.container.Module.stop(Module.java:478)
org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:169)
org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:158)
java.lang.Thread.run(Thread.java:722)


I looked at org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.contextDisposed():

	@PreDestroy
	public void contextDisposed() {
		eventBroker.unsubscribe(itemUpdater);
		eventBroker.unsubscribe(selectionUpdater);
		eventBroker.unsubscribe(enabledUpdater);
		eventBroker.unsubscribe(toBeRenderedUpdater);

		ContextInjectionFactory.uninject(MenuManagerEventHelper.showHelper,
				context);
		MenuManagerEventHelper.showHelper = null;
		ContextInjectionFactory.uninject(MenuManagerEventHelper.hideHelper,
				context);
		MenuManagerEventHelper.hideHelper = null;

		context.remove(MenuManagerRendererFilter.class);
		Display display = context.get(Display.class);
		if (display != null && !display.isDisposed() && rendererFilter != null) {
			display.removeFilter(SWT.Show, rendererFilter);
			display.removeFilter(SWT.Hide, rendererFilter);
			display.removeFilter(SWT.Dispose, rendererFilter);
		}
		if (rendererFilter != null) {
			ContextInjectionFactory.uninject(rendererFilter, context);
			rendererFilter = null;
		}
		context.remove(MenuManagerRenderer.class);
	}


and the problem occurs in the line

display.removeFilter(SWT.Show, rendererFilter);


Can you guys help me find a solution?
Thank you very much,
Matthias
Re: Invalid Thread Access in MenuManagerRenderer.contextDisposed [message #1182543 is a reply to message #1182436] Tue, 12 November 2013 08:58 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5310
Registered: July 2009
Senior Member
So when does it happen? It looks like the framework is going down and
then it disposes context on a none-ui thread.

To me this looks like a bug in EclipseContextOSGi.bundleChanged which
should make sure the disposal done on the UI-Thread - problem might be
at this level we don't have such an information because we are in the core.

Tom

On 12.11.13 08:25, Matthias Nick wrote:
> Hi, when I close my RCP application I get an invalid thread access:
>
>
> 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.di.InjectorImpl.processAnnotated(InjectorImpl.java:877)
>
> at
> org.eclipse.e4.core.internal.di.InjectorImpl.disposed(InjectorImpl.java:386)
>
> at
> org.eclipse.e4.core.internal.di.Requestor.disposed(Requestor.java:132)
> at
> org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:76)
>
> at
> org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:107)
>
> at
> org.eclipse.e4.core.internal.contexts.TrackableComputationExt.handleInvalid(TrackableComputationExt.java:70)
>
> at
> org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:171)
>
> at
> org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:160)
>
> at
> org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.dispose(EclipseContextOSGi.java:100)
>
> at
> org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.bundleChanged(EclipseContextOSGi.java:131)
>
> at
> org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:892)
>
> at
> org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
>
> at
> org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
>
> at
> org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:165)
>
> at
> org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:75)
>
> at
> org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:67)
>
> at
> org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:87)
>
> at org.eclipse.osgi.container.Module.publishEvent(Module.java:454)
> at org.eclipse.osgi.container.Module.doStop(Module.java:609)
> at org.eclipse.osgi.container.Module.stop(Module.java:476)
> at org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:165)
> at
> org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:216)
>
> at java.lang.Thread.run(Thread.java:722)
> Caused by: org.eclipse.swt.SWTException: Invalid thread access
> org.eclipse.swt.SWT.error(SWT.java:4419)
> org.eclipse.swt.SWT.error(SWT.java:4334)
> org.eclipse.swt.SWT.error(SWT.java:4305)
> org.eclipse.swt.widgets.Display.error(Display.java:1257)
> org.eclipse.swt.widgets.Display.checkDevice(Display.java:763)
> org.eclipse.swt.widgets.Display.removeFilter(Display.java:4062)
> org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.contextDisposed(MenuManagerRenderer.java:254)
>
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>
> java.lang.reflect.Method.invoke(Method.java:601)
> org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
>
> org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:877)
>
> org.eclipse.e4.core.internal.di.InjectorImpl.disposed(InjectorImpl.java:386)
>
> org.eclipse.e4.core.internal.di.Requestor.disposed(Requestor.java:132)
> org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:76)
>
> org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:107)
>
> org.eclipse.e4.core.internal.contexts.TrackableComputationExt.handleInvalid(TrackableComputationExt.java:70)
>
> org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:171)
>
> org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:160)
>
> org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.dispose(EclipseContextOSGi.java:100)
>
> org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.bundleChanged(EclipseContextOSGi.java:131)
>
> org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:902)
>
> org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
>
> org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
>
> org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:165)
>
> org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:75)
>
> org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:67)
>
> org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:89)
>
> org.eclipse.osgi.container.Module.publishEvent(Module.java:456)
> org.eclipse.osgi.container.Module.doStop(Module.java:611)
> org.eclipse.osgi.container.Module.stop(Module.java:478)
> org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:169)
> org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:158)
>
> java.lang.Thread.run(Thread.java:722)
>
>
> I looked at
> org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.contextDisposed():
>
>
>
> @PreDestroy
> public void contextDisposed() {
> eventBroker.unsubscribe(itemUpdater);
> eventBroker.unsubscribe(selectionUpdater);
> eventBroker.unsubscribe(enabledUpdater);
> eventBroker.unsubscribe(toBeRenderedUpdater);
>
> ContextInjectionFactory.uninject(MenuManagerEventHelper.showHelper,
> context);
> MenuManagerEventHelper.showHelper = null;
> ContextInjectionFactory.uninject(MenuManagerEventHelper.hideHelper,
> context);
> MenuManagerEventHelper.hideHelper = null;
>
> context.remove(MenuManagerRendererFilter.class);
> Display display = context.get(Display.class);
> if (display != null && !display.isDisposed() && rendererFilter
> != null) {
> display.removeFilter(SWT.Show, rendererFilter);
> display.removeFilter(SWT.Hide, rendererFilter);
> display.removeFilter(SWT.Dispose, rendererFilter);
> }
> if (rendererFilter != null) {
> ContextInjectionFactory.uninject(rendererFilter, context);
> rendererFilter = null;
> }
> context.remove(MenuManagerRenderer.class);
> }
>
>
> and the problem occurs in the line
>
>
> display.removeFilter(SWT.Show, rendererFilter);
>
>
> Can you guys help me find a solution?
> Thank you very much,
> Matthias
Re: Invalid Thread Access in MenuManagerRenderer.contextDisposed [message #1182555 is a reply to message #1182543] Tue, 12 November 2013 09:06 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias Nick
Messages: 172
Registered: August 2013
Senior Member
Hi Tom,
thanks for your answer. It happens when I close my RCP application.

Matthias
Re: Invalid Thread Access in MenuManagerRenderer.contextDisposed [message #1182556 is a reply to message #1182555] Tue, 12 November 2013 09:08 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5310
Registered: July 2009
Senior Member
Is there anything special about the closing? When the Bundle is brought
down the context should have been disposed already :-(

Tom

On 12.11.13 10:06, Matthias Nick wrote:
> Hi Tom,
> thanks for your answer. It happens when I close my RCP application.
>
> Matthias
Re: Invalid Thread Access in MenuManagerRenderer.contextDisposed [message #1183921 is a reply to message #1182556] Wed, 13 November 2013 05:28 Go to previous messageGo to next message
sumit singh is currently offline sumit singh
Messages: 131
Registered: October 2012
Location: Bangalore
Senior Member

Execute your UI related code in :
 Display.getDefault().syncExec(
   new Runnable(){
       public void run(){
        // your UI code  
      } 
   }
 );
Re: Invalid Thread Access in MenuManagerRenderer.contextDisposed [message #1194025 is a reply to message #1183921] Mon, 18 November 2013 09:46 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias Nick
Messages: 172
Registered: August 2013
Senior Member
Hi sumit, I aggree. I know that the code is running in the wrong thread, however how can I find the position where the code should be applied? The stacktrace does not help me very much...

Can you give me some hints?
Re: Invalid Thread Access in MenuManagerRenderer.contextDisposed [message #1196050 is a reply to message #1194025] Tue, 19 November 2013 08:11 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias Nick
Messages: 172
Registered: August 2013
Senior Member
I was able to solve my problem. I disposed the display so that MenuManagerRenderer.contextDisposed() can't run into the if-block. However I think this is still an Eclipse Bug.
Thanks for your help though.
Re: Invalid Thread Access in MenuManagerRenderer.contextDisposed [message #1196083 is a reply to message #1194025] Tue, 19 November 2013 08:32 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias Nick
Messages: 172
Registered: August 2013
Senior Member
Created bugzilla entry: https://bugs.eclipse.org/bugs/show_bug.cgi?id=422027
Re: Invalid Thread Access in MenuManagerRenderer.contextDisposed [message #1196381 is a reply to message #1196083] Tue, 19 November 2013 11:41 Go to previous message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

Rather than Display.getDefault().etc... have the UISynchronize injected and use it's sync, async method.
Previous Topic:Contributing to any e4 Application
Next Topic:Project specific preferences
Goto Forum:
  


Current Time: Mon Sep 15 04:21:18 GMT 2014

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

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