Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 497857

Summary: WorkbenchWindowControlContribution createControl Window called twice
Product: [Eclipse Project] Platform Reporter: Patrick Chuong <pchuong>
Component: UIAssignee: Platform-UI-Inbox <Platform-UI-Inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: bsd, loskutov
Version: 3.8.2   
Target Milestone: ---   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=427452
Whiteboard: stalebug
Attachments:
Description Flags
demo project none

Description Patrick Chuong CLA 2016-07-13 13:38:01 EDT
I have a WorkbenchWindowControlContribution. In the createControl method, I call PlatformUI.getWorkbench().getActiveWorkbenchWindow(). This causes another call into the createControl method again. This happen during eclipse startup with a clean workspace. Below is the callstack. You can see the LicenseStatusBar.createControl() is called twice in the stack. The second createControl is triggered by the Workbench.getActiveWorkbenchWindow() call in the first createControl method.

Here are my observations: 
- the first time the createControl is call, the workbenchwindow is null, maybe it is still under construction. (What is the proper method to get teh workbenchwindow? I need the workbenchwindow or the WorkbenchWindowControlContribution should set the workbenchwindow in the construction other than NULL.
- the second time the createControl is call, the workbenchwindow is available for the WorkbenchWindowControlContribution.

This issue might be related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=427452.


LicenseMonitor.addStatusBar(CCSStatusBar) line: 452	
LicenseStatusBar.fill() line: 52	
LicenseStatusBar(CCSStatusBar).createControl(Composite) line: 39	
LicenseStatusBar(WorkbenchWindowControlContribution).delegateCreateControl(Composite) line: 105	
CompatibilityWorkbenchWindowControlContribution.construct(MWindow, MToolControl, Composite) line: 90	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
Method.invoke(Object, Object...) line: not available	
MethodRequestor.execute() line: 54	
InjectorImpl.processAnnotated(Class<Annotation>, Object, Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier, ArrayList<Class<?>>) line: 966	
InjectorImpl.inject(Object, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 151	
InjectorImpl.internalMake(Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 375	
InjectorImpl.make(Class<T>, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 308	
ContextInjectionFactory.make(Class<T>, IEclipseContext, IEclipseContext) line: 186	
ReflectionContributionFactory.createFromBundle(Bundle, IEclipseContext, IEclipseContext, URI) line: 108	
ReflectionContributionFactory.doCreate(String, IEclipseContext, IEclipseContext) line: 74	
ReflectionContributionFactory.create(String, IEclipseContext, IEclipseContext) line: 51	
ToolControlContribution.createControl(Composite) line: 58	
ToolControlContribution(ControlContribution).fill(ToolBar, int) line: 101	
ToolBarManager.update(boolean) line: 343	
ToolBarManagerRenderer.subscribeTopicUpdateToBeRendered(Event) line: 213	
GeneratedMethodAccessor5.invoke(Object, Object[]) line: not available	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
Method.invoke(Object, Object...) line: not available	
MethodRequestor.execute() line: 54	
UIEventObjectSupplier$UIEventHandler$1.run() line: 56	
UISynchronizer(Synchronizer).syncExec(Runnable) line: 233	
UISynchronizer.syncExec(Runnable) line: 145	
Display.syncExec(Runnable) line: 4813	
E4Application$1.syncExec(Runnable) line: 211	
UIEventObjectSupplier$UIEventHandler.handleEvent(Event) line: 53	
EventHandlerWrapper.handleEvent(Event, Permission) line: 201	
EventHandlerTracker.dispatchEvent(EventHandlerWrapper, Permission, int, Event) line: 197	
EventHandlerTracker.dispatchEvent(Object, Object, int, Object) line: 1	
EventManager.dispatchEvent(Set<Entry<K,V>>, EventDispatcher<K,V,E>, int, E) line: 230	
ListenerQueue<K,V,E>.dispatchEventSynchronous(int, E) line: 148	
EventAdminImpl.dispatchEvent(Event, boolean) line: 135	
EventAdminImpl.sendEvent(Event) line: 78	
EventComponent.sendEvent(Event) line: 39	
EventBroker.send(String, Object) line: 94	
UIEventPublisher.notifyChanged(Notification) line: 60	
HandledToolItemImpl(BasicNotifierImpl).eNotify(Notification) line: 374	
HandledToolItemImpl(UIElementImpl).setVisible(boolean) line: 345	
ToolBarContributionRecord.updateVisibility(IEclipseContext) line: 74	
ToolBarManagerRenderer$5.changed(IEclipseContext) line: 479	
TrackableComputationExt.update(ContextChangeEvent) line: 114	
EclipseContext.processScheduled(Set<Scheduled>) line: 343	
EclipseContext.set(String, Object) line: 358	
EclipseContext.activate() line: 663	
PartActivationHistory.activate(MPart, boolean) line: 57	
PartServiceImpl.activate(MPart, boolean, boolean) line: 747	
PartServiceImpl.switchPerspective(MPerspective) line: 642	
PerspectiveStackRenderer.showTab(MUIElement) line: 106	
LazyStackRenderer$1.handleEvent(Event) line: 72	
UIEventHandler$1.run() line: 40	
UISynchronizer(Synchronizer).syncExec(Runnable) line: 233	
UISynchronizer.syncExec(Runnable) line: 145	
Display.syncExec(Runnable) line: 4813	
E4Application$1.syncExec(Runnable) line: 211	
UIEventHandler.handleEvent(Event) line: 36	
EventHandlerWrapper.handleEvent(Event, Permission) line: 201	
EventHandlerTracker.dispatchEvent(EventHandlerWrapper, Permission, int, Event) line: 197	
EventHandlerTracker.dispatchEvent(Object, Object, int, Object) line: 1	
EventManager.dispatchEvent(Set<Entry<K,V>>, EventDispatcher<K,V,E>, int, E) line: 230	
ListenerQueue<K,V,E>.dispatchEventSynchronous(int, E) line: 148	
EventAdminImpl.dispatchEvent(Event, boolean) line: 135	
EventAdminImpl.sendEvent(Event) line: 78	
EventComponent.sendEvent(Event) line: 39	
EventBroker.send(String, Object) line: 94	
UIEventPublisher.notifyChanged(Notification) line: 60	
PerspectiveStackImpl(BasicNotifierImpl).eNotify(Notification) line: 374	
PerspectiveStackImpl.setSelectedElement(MPerspective) line: 135	
PerspectiveStackImpl.setSelectedElement(MUIElement) line: 1	
WorkbenchPage.setPerspective(IPerspectiveDescriptor) line: 4091	
WorkbenchWindow.setup() line: 738	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
Method.invoke(Object, Object...) line: not available	
MethodRequestor.execute() line: 54	
InjectorImpl.processAnnotated(Class<Annotation>, Object, Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier, ArrayList<Class<?>>) line: 966	
InjectorImpl.inject(Object, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 151	
InjectorImpl.inject(Object, PrimaryObjectSupplier) line: 118	
ContextInjectionFactory.inject(Object, IEclipseContext) line: 73	
Workbench.createWorkbenchWindow(IAdaptable, IPerspectiveDescriptor, MWindow, boolean) line: 1525	
Workbench.getActiveWorkbenchWindow() line: 1499	
LicenseMonitor.addStatusBar(CCSStatusBar) line: 449	
LicenseStatusBar.fill() line: 52	
LicenseStatusBar(CCSStatusBar).createControl(Composite) line: 39	
LicenseStatusBar(WorkbenchWindowControlContribution).delegateCreateControl(Composite) line: 105	
CompatibilityWorkbenchWindowControlContribution.construct(MWindow, MToolControl, Composite) line: 90	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
Method.invoke(Object, Object...) line: not available	
MethodRequestor.execute() line: 54	
InjectorImpl.processAnnotated(Class<Annotation>, Object, Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier, ArrayList<Class<?>>) line: 966	
InjectorImpl.inject(Object, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 151	
InjectorImpl.internalMake(Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 375	
InjectorImpl.make(Class<T>, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 308	
ContextInjectionFactory.make(Class<T>, IEclipseContext, IEclipseContext) line: 186	
ReflectionContributionFactory.createFromBundle(Bundle, IEclipseContext, IEclipseContext, URI) line: 108	
ReflectionContributionFactory.doCreate(String, IEclipseContext, IEclipseContext) line: 74	
ReflectionContributionFactory.create(String, IEclipseContext, IEclipseContext) line: 51	
ToolControlContribution.createControl(Composite) line: 58	
ToolControlContribution(ControlContribution).fill(ToolBar, int) line: 101	
ToolBarManager.update(boolean) line: 343	
ToolBarManagerRenderer.subscribeTopicUpdateToBeRendered(Event) line: 213	
GeneratedMethodAccessor5.invoke(Object, Object[]) line: not available	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
Method.invoke(Object, Object...) line: not available	
MethodRequestor.execute() line: 54	
UIEventObjectSupplier$UIEventHandler$1.run() line: 56	
UISynchronizer(Synchronizer).syncExec(Runnable) line: 233	
UISynchronizer.syncExec(Runnable) line: 145	
Display.syncExec(Runnable) line: 4813	
E4Application$1.syncExec(Runnable) line: 211	
UIEventObjectSupplier$UIEventHandler.handleEvent(Event) line: 53	
EventHandlerWrapper.handleEvent(Event, Permission) line: 201	
EventHandlerTracker.dispatchEvent(EventHandlerWrapper, Permission, int, Event) line: 197	
EventHandlerTracker.dispatchEvent(Object, Object, int, Object) line: 1	
EventManager.dispatchEvent(Set<Entry<K,V>>, EventDispatcher<K,V,E>, int, E) line: 230	
ListenerQueue<K,V,E>.dispatchEventSynchronous(int, E) line: 148	
EventAdminImpl.dispatchEvent(Event, boolean) line: 135	
EventAdminImpl.sendEvent(Event) line: 78	
EventComponent.sendEvent(Event) line: 39	
EventBroker.send(String, Object) line: 94	
UIEventPublisher.notifyChanged(Notification) line: 60	
ToolControlImpl(BasicNotifierImpl).eNotify(Notification) line: 374	
ToolControlImpl(UIElementImpl).setVisible(boolean) line: 345	
ToolBarContributionRecord.updateVisibility(IEclipseContext) line: 74	
ToolBarManagerRenderer$5.changed(IEclipseContext) line: 479	
TrackableComputationExt.update(ContextChangeEvent) line: 114	
EclipseContext.runAndTrack(RunAndTrack) line: 324	
ToolBarManagerRenderer.processAddition(MToolBar, ToolBarManager, MToolBarContribution) line: 471	
ToolBarManagerRenderer.generateContributions(MToolBar, List<MToolBarContribution>) line: 447	
ToolBarManagerRenderer.processContribution(MToolBar, String) line: 413	
ToolBarManagerRenderer.createWidget(MUIElement, Object) line: 373	
PartRenderingEngine.createWidget(MUIElement, Object) line: 975	
PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 651	
PartRenderingEngine.safeCreateGui(MUIElement) line: 757	
PartRenderingEngine.access$0(PartRenderingEngine, MUIElement) line: 728	
PartRenderingEngine$2.run() line: 722	
SafeRunner.run(ISafeRunnable) line: 42	
PartRenderingEngine.createGui(MUIElement) line: 706	
PartRenderingEngine.subscribeChildrenHandler(Event) line: 296	
GeneratedMethodAccessor8.invoke(Object, Object[]) line: not available	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
Method.invoke(Object, Object...) line: not available	
MethodRequestor.execute() line: 54	
EventObjectSupplier$DIEventHandler.handleEvent(Event) line: 80	
EventHandlerWrapper.handleEvent(Event, Permission) line: 201	
EventHandlerTracker.dispatchEvent(EventHandlerWrapper, Permission, int, Event) line: 197	
EventHandlerTracker.dispatchEvent(Object, Object, int, Object) line: 1	
EventManager.dispatchEvent(Set<Entry<K,V>>, EventDispatcher<K,V,E>, int, E) line: 230	
ListenerQueue<K,V,E>.dispatchEventSynchronous(int, E) line: 148	
EventAdminImpl.dispatchEvent(Event, boolean) line: 135	
EventAdminImpl.sendEvent(Event) line: 78	
EventComponent.sendEvent(Event) line: 39	
EventBroker.send(String, Object) line: 94	
UIEventPublisher.notifyChanged(Notification) line: 60	
TrimBarImpl(BasicNotifierImpl).eNotify(Notification) line: 374	
ElementContainerImpl$1(EcoreEList<E>).dispatchNotification(Notification) line: 249	
ElementContainerImpl$1(NotifyingListImpl<E>).addUnique(int, E) line: 356	
ElementContainerImpl$1(AbstractEList<E>).add(int, E) line: 341	
ContributionsAnalyzer.processAddition(MTrimBar, MTrimContribution, List<MTrimElement>, HashSet<String>) line: 370	
TrimBarRenderer.addTrimContributions(MTrimBar, ArrayList<MTrimContribution>, IEclipseContext, ExpressionContext) line: 171	
TrimBarRenderer.processContents(MElementContainer<MUIElement>) line: 143	
PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 665	
PartRenderingEngine$1.run() line: 536	
SafeRunner.run(ISafeRunnable) line: 42	
PartRenderingEngine.createGui(MUIElement, Object, IEclipseContext) line: 520	
WBWRenderer.processContents(MElementContainer<MUIElement>) line: 747	
PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 665	
PartRenderingEngine.safeCreateGui(MUIElement) line: 757	
PartRenderingEngine.access$0(PartRenderingEngine, MUIElement) line: 728	
PartRenderingEngine$2.run() line: 722	
SafeRunner.run(ISafeRunnable) line: 42	
PartRenderingEngine.createGui(MUIElement) line: 706	
PartRenderingEngine$4.run() line: 1059	
Realm.runWithDefault(Realm, Runnable) line: 336	
PartRenderingEngine.run(MApplicationElement, IEclipseContext) line: 1022	
E4Workbench.createAndRunUI(MApplicationElement) line: 150	
Workbench$5.run() line: 687	
Realm.runWithDefault(Realm, Runnable) line: 336	
Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 604	
PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 148	
IDEApplication.start(IApplicationContext) line: 138	
EclipseAppHandle.run(Object) line: 196	
EclipseAppLauncher.runApplication(Object) line: 134	
EclipseAppLauncher.start(Object) line: 104	
EclipseStarter.run(Object) line: 388	
EclipseStarter.run(String[], Runnable) line: 243	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
Method.invoke(Object, Object...) line: not available	
Main.invokeFramework(String[], URL[]) line: 673	
Main.basicRun(String[]) line: 610	
Main.run(String[]) line: 1519	
Main.main(String[]) line: 1492
Comment 1 Andrey Loskutov CLA 2016-07-13 13:44:14 EDT
I've seen the same on 3.8.2 (sure, stack was different) but the problem was that trim contribution was created twice on startup.
Comment 2 Andrey Loskutov CLA 2016-07-13 13:45:40 EDT
Patrick, how do you contribute your controls? Can you share a minimal example?
Comment 3 Patrick Chuong CLA 2016-07-19 16:21:16 EDT
Created attachment 263193 [details]
demo project
Comment 4 Patrick Chuong CLA 2016-07-19 16:24:29 EDT
Hi Andrey, after spending half a day creating an reproducible example. I finally found the right receipt. Creating the example was easy, but having it to reproduce the issue was some what challenging... I hope you can reproduce it and have a solution for it.

I have the attached example imported into my development workspace (neon), launch eclipse using the "Run an application" selected (org.eclipse.ui.ide.workbench). Also have the workspace clear and clear the configuration area before launching checked.

It is a combination of the property tester, run as applicatoin, and clearing the workspace/configuration that trigger creating multiple workbenchs.
Comment 5 Brian de Alwis CLA 2016-07-20 23:57:44 EDT
Why aren't you just calling WorkbenchWindowControlContribution#getWorkbenchWindow() from within your createControl()?

You should almost never ever need to call PlatformUI.getWorkbench().getActiveWorkbenchWindow().
Comment 6 Patrick Chuong CLA 2016-07-26 14:30:57 EDT
(In reply to Brian de Alwis from comment #5)
> Why aren't you just calling
> WorkbenchWindowControlContribution#getWorkbenchWindow() from within your
> createControl()?
> 
> You should almost never ever need to call
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().

Because WorkbenchWindowControlContribution#getWorkbenchWindow() returns null. I believe it is related to bug 427452. Calling getActiveWorkbenchWindow() shouldn't cause the WorkbenchWindowControlContribution#createControl to be called twice.
Comment 7 Eclipse Genie CLA 2020-04-10 18:54:32 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.