I have a PropertyTester
that is called via a visibleWhen
on the main toolbar, and on application start throws the following exception:
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
at java.util.ArrayList$Itr.next(ArrayList.java:851)
at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarContributionRecord.updateVisibility(ToolBarContributionRecord.java:70)
at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer$5.changed(ToolBarManagerRenderer.java:479)
at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:114)
at org.eclipse.e4.core.internal.contexts.EclipseContext.runAndTrack(EclipseContext.java:324)
at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.processAddition(ToolBarManagerRenderer.java:471)
at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.generateContributions(ToolBarManagerRenderer.java:447)
at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.processContribution(ToolBarManagerRenderer.java:413)
I really think E4 should be able to cope with a tool item "suddenly" disappearing. Moreover since the property tester in question ALWAYS returns false, the tool item was not even visible to begin with.
I can trace the exception to the following line (bear in mind that the property tester that causes the exception is not even present in the stack trace):
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
If I add the line in the test(...)
method of the PropertyTester
the exception occurs. If I remove it it does not. So a minimal example to show the bug is:
public final class MyPropertyTester extends PropertyTester {
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
return false;
}
}
I'm absolutely stumped why this exception occurs and how I could possible prevent it from happening. getActiveWorkbenchWindow()
never returns null or throws an exception. IWorkbench#isStarting
does not return true either, even though my guess would be that there is still some kind of initialization running when the error occurs.
(Note: other than being really ugly, the exception does not affect how the application works.)
How can I prevent this exception?