Bug 175192 [Viewers] Loop exception on shutdown
I've been getting a spurious error on shutdown during my debugging sessions recently. Sorry but I haven't been able to nail down the circumstances that cause it to happen. Here's the callstack: org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.IllegalArgumentException: Index out of bounds) at org.eclipse.swt.SWT.error(SWT.java:3478) at org.eclipse.swt.SWT.error(SWT.java:3401) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:126) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3467) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3107) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2264) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2228) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2103) at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:457) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:452) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:101) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:146) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:169) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:615) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:476) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:416) at org.eclipse.equinox.launcher.Main.run(Main.java:1124) at org.eclipse.equinox.launcher.Main.main(Main.java:1099) Caused by: java.lang.IllegalArgumentException: Index out of bounds at org.eclipse.swt.SWT.error(SWT.java:3462) at org.eclipse.swt.SWT.error(SWT.java:3401) at org.eclipse.swt.SWT.error(SWT.java:3372) at org.eclipse.swt.widgets.TreeItem.findPrevious(TreeItem.java:222) at org.eclipse.swt.widgets.TreeItem.<init>(TreeItem.java:189) at org.eclipse.jface.viewers.TreeViewer.createNewRowPart(TreeViewer.java:686) at org.eclipse.jface.viewers.TreeViewer.newItem(TreeViewer.java:315) at org.eclipse.jface.viewers.AbstractTreeViewer.createTreeItem(AbstractTreeViewer.java:798) at org.eclipse.jface.viewers.AbstractTreeViewer.insert(AbstractTreeViewer.java:2818) at org.eclipse.debug.internal.ui.viewers.model.InternalTreeModelViewer.insert(InternalTreeModelViewer.java:422) at org.eclipse.debug.internal.ui.viewers.model.ChildrenUpdate.performUpdate(ChildrenUpdate.java:70) at org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor$1.runInUIThread(ViewerUpdateMonitor.java:58) at org.eclipse.ui.progress.UIJob$1.run(UIJob.java:94) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123) ... 23 more
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java
}
				}
				if (add) {
					filtered.add(elements[i]);
				}
			}
			return filtered.toArray();
		}
		return elements;
	}
	/**
	 * Create the new elements in the parent widget. If the child already exists
	 * do nothing.
	 * 
	 * @param widget
	 * @param elements
	 *            Sorted list of elements to add.
	 */
	private void createAddedElements(Widget widget, Object[] elements) {
		if (elements.length == 1) {
			if (equals(elements[0], widget.getData())) {
				return;
			}
		}
		ViewerComparator comparator = getComparator();
		TreePath parentPath = internalGetSorterParentPath(widget, comparator);
		Item[] items = getChildren(widget);
		
		
		int lastInsertion = 0;