Community
Participate
Working Groups
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.
But it's only actually creating one instance of WorkbenchWindow, correct?
Correct, but it is calling a lot of code to get to that point. Up to and including PerspectiveRegistry.getDefaultPerspective() all 10 times
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.
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)
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.
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.
Opened Bug 448150 for PartSite calling the method several times.
Proposed fix for this bug report: https://git.eclipse.org/r/#/c/35280/
Fixed with http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=6112d459116fae08a67d78dfa7fcc6b9ed53b938
.