Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 366708 - [Workbench] Workbench.openWorkbenchWindow() calls createWorkbenchWindow multiple times
Summary: [Workbench] Workbench.openWorkbenchWindow() calls createWorkbenchWindow multi...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: 4.5 M3   Edit
Assignee: Lars Vogel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-14 09:57 EST by Dean Roberts CLA
Modified: 2014-10-31 07:54 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dean Roberts CLA 2011-12-14 09:57:59 EST
Workbench.openWorkbenchWindow() calls createWorkbenchWindow 10 times

Run the automated test case org.eclipse.ui.tests.api.IWorkbenchTest.testOpenWorkbenchWindow2

Place a breakpoint in the test on the line that calls .openWorkbenchWindow and the following line.

Once the 1st breakpoint is hit, add a breakpoint to Workbench.createWorkbenchWindow(IAdaptable, IPerspectiveDescriptor, Mwindow, boolean)

Resume

Note that createWorkbenchWindow is called 10 times.
Comment 1 Remy Suen CLA 2011-12-14 15:17:24 EST
But it's only actually creating one instance of WorkbenchWindow, correct?
Comment 2 Dean Roberts CLA 2011-12-14 15:20:52 EST
Correct, but it is calling a lot of code to get to that point.

Up to and including PerspectiveRegistry.getDefaultPerspective() all 10 times
Comment 3 Eric Moffatt CLA 2013-10-21 13:54:36 EDT
Actually, it's the code in 'getActiveWorkbenchWindow' which *always* seems to fail the model tests and resorts to the final plan...create one. This actually gets called all the time, quite dangerous.
Comment 4 Henno Vermeulen CLA 2014-02-07 07:59:10 EST
Could it be that PlatformUI.getWorkbench().getActiveWorkbenchWindow() creates one if it is not fully created yet, but is still in the progress of being created?

I seem to be getting a quite confusing problem with creating workbench control contributions to the toolbar as in https://bugs.eclipse.org/bugs/show_bug.cgi?id=427452

Due to that bug in 4.4M6, the first time WorkbenchWindowControlContribution.createControl() method is called, the workbench window isn't fully available yet. When I then call 

PlatformUI.getWorkbench().getActiveWorkbenchWindow() 

this somehow resulted in an attempt to create a workbench window which recursively calls the createControl() method again!

This second call seems to succeed. It seems that it disposes the old partially initialized workbench because after it succeeds it returns to the first call to createControl. This call then fails with an SWT exception that the parent composite is disposed.

I also seem to be getting:

!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.e4.ui.workbench.swt".
!STACK 0
java.util.ConcurrentModificationException
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:859)
	at java.util.ArrayList$Itr.next(ArrayList.java:831)
	at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarContributionRecord.updateVisibility(ToolBarContributionRecord.java:68)
Comment 5 Henno Vermeulen CLA 2014-02-07 08:03:49 EST
I think the fact is that getActiveWorkbenchWindow() can get called recursively because any code is allowed to call the static method PlatformUI.getWorkbench().

I see that an "initializationDone" boolean is checked, but it isn't true yet for a recusive call. Perhaps it should become "initializationStarted" which must be set to true before calling createWorkbenchWindow.
Comment 6 Lars Vogel CLA 2014-10-21 18:58:13 EDT
I added the following test code add beginning of the createWorkbenchWindow method

// static field
System.out.println("Number called " + value++); //$NON-NLS-1$

StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
		for (int i = 1; i < stackTraceElements.length && i<=4; i++) {
			StackTraceElement stackTraceElement = stackTraceElements[i];
			System.out.println(stackTraceElement.getClassName() + " Method " + stackTraceElement.getMethodName()); //$NON-NLS-1$
		}
		System.out.println(""); //$NON-NLS-1$

It shows that the method is called 21 times during startup.
Comment 7 Lars Vogel CLA 2014-10-21 18:58:38 EDT
Opened Bug 448150 for PartSite calling the method several times.
Comment 8 Lars Vogel CLA 2014-10-21 19:04:03 EDT
Proposed fix for this bug report:

https://git.eclipse.org/r/#/c/35280/
Comment 10 Lars Vogel CLA 2014-10-31 07:54:44 EDT
.