I have a code which sets the active selection of the ESelectionService
when the user selects something in the tree. Like here:
treeViewer.addSelectionChangedListener(new SelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (selectionService != null) {
selectionService.setSelection(((IStructuredSelection) event.getSelection()).getFirstElement());
}
}
});
where selectionService
is being injected. So far so good.
I also have some command handlers with their own canExecute()
methods. In these methods I check the current selection (which is also being injected) and decide if the canExecute()
method should return true or false. What I also do in this method is, I also change the visibility of the corresponding HandledToolItem
- like here https://stackoverflow.com/a/23602909/2097228.
Now what I experience is that sometimes the call to the setSelection
method of the ESelectionService
throws a ConcurrentModificationException
. This actually occurs when the ToolItemUpdater accesses the itemsToCheck
ArrayList
.
Is my approach error-prone or is this just a bug in 4.4?
Here is the stacktrace:
Exception occurred
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
at java.util.ArrayList$Itr.next(Unknown Source)
at org.eclipse.e4.ui.workbench.renderers.swt.ToolItemUpdater.updateContributionItems(ToolItemUpdater.java:36)
at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer$8.changed(ToolBarManagerRenderer.java:367)
at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:110)
at org.eclipse.e4.core.internal.contexts.EclipseContext.processScheduled(EclipseContext.java:338)
at org.eclipse.e4.core.internal.contexts.EclipseContext.set(EclipseContext.java:352)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$4.changed(E4Application.java:842)
at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:110)
at org.eclipse.e4.core.internal.contexts.EclipseContext.processScheduled(EclipseContext.java:338)
at org.eclipse.e4.core.internal.contexts.EclipseContext.set(EclipseContext.java:352)
at org.eclipse.e4.ui.internal.workbench.SelectionAggregator$7.changed(SelectionAggregator.java:228)
at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:110)
at org.eclipse.e4.core.internal.contexts.EclipseContext.processScheduled(EclipseContext.java:338)
at org.eclipse.e4.core.internal.contexts.EclipseContext.set(EclipseContext.java:352)
at org.eclipse.e4.ui.internal.workbench.SelectionServiceImpl.setSelection(SelectionServiceImpl.java:31)
at com.e4test.parts.SamplePart$TreeViewerSelectionListener.selectionChanged(SamplePart.java:116)