Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 93234

Summary: ClassCast Exception when selecting Search Result Items
Product: [Eclipse Project] Platform Reporter: Stefan Holzknecht <s.holzknecht>
Component: SearchAssignee: Platform-Search-Inbox <platform-search-inbox>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 RC2   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Stefan Holzknecht CLA 2005-04-29 03:39:51 EDT
In the classic search result view a class cast exception is thrown when an item
 gets selected. The exeption is thrown in the IActionFilter WorkbenchProject
which adapts to the search result item:
SearchResultViewEntry:
public Object getAdapter(Class adapter) {
		Object adapted= super.getAdapter(adapter);
		if (adapted == null && !adapter.equals(IResource.class) &&
!adapter.equals(IMarker.class)) {
			return getResource().getAdapter(adapter);
		}
		return adapted;
	}

This filter assumes that it is assigned to a reosurce only:
WorkbenchProject:

    public boolean testAttribute(Object target, String name, String value) {
        IProject proj = (IProject) target;
---> here the exception gets thrown; the target is of type SearchResultViewEntry.

I suggest that either the search result entry should not return just adapters
that actually adapt to resources or the filter should check the right type in
its test method.

The full stacktrace:
!ENTRY org.eclipse.ui.workbench 4 2 2005-04-29 09:19:34.984
!MESSAGE Problems occurred when invoking code from plug-in:
"org.eclipse.ui.workbench".
!STACK 0
java.lang.ClassCastException: org.eclipse.search.internal.ui.SearchResultViewEntry
	at
org.eclipse.ui.internal.ide.model.WorkbenchProject.testAttribute(WorkbenchProject.java:99)
	at
org.eclipse.ui.internal.ActionExpression$ObjectStateExpression.preciselyMatches(ActionExpression.java:467)
	at
org.eclipse.ui.internal.ActionExpression$ObjectStateExpression.isEnabledFor(ActionExpression.java:435)
	at
org.eclipse.ui.internal.ActionExpression$AndExpression.isEnabledFor(ActionExpression.java:395)
	at
org.eclipse.ui.internal.ActionExpression$SingleExpression.isEnabledFor(ActionExpression.java:308)
	at org.eclipse.ui.internal.ActionExpression.isEnabledFor(ActionExpression.java:121)
	at org.eclipse.ui.internal.ActionExpression.isEnabledFor(ActionExpression.java:156)
	at org.eclipse.ui.SelectionEnabler.isEnabledFor(SelectionEnabler.java:305)
	at org.eclipse.ui.SelectionEnabler.isEnabledForSelection(SelectionEnabler.java:187)
	at org.eclipse.ui.internal.PluginAction.refreshEnablement(PluginAction.java:197)
	at org.eclipse.ui.internal.PluginAction.selectionChanged(PluginAction.java:271)
	at org.eclipse.ui.internal.PluginAction.selectionChanged(PluginAction.java:292)
	at
org.eclipse.ui.internal.AbstractSelectionService$3.run(AbstractSelectionService.java:160)
	at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1021)
	at org.eclipse.core.runtime.Platform.run(Platform.java:757)
	at
org.eclipse.ui.internal.AbstractSelectionService.fireSelection(AbstractSelectionService.java:158)
	at
org.eclipse.ui.internal.AbstractSelectionService$1.selectionChanged(AbstractSelectionService.java:66)
	at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
	at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1021)
	at org.eclipse.core.runtime.Platform.run(Platform.java:757)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:40)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:148)
	at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
	at
org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:1691)
	at
org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1359)
	at
org.eclipse.search.internal.ui.SearchResultViewer.selectResult(SearchResultViewer.java:535)
	at
org.eclipse.search.internal.ui.SearchResultViewer.inputChanged(SearchResultViewer.java:268)
	at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:248)
	at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1324)
	at
org.eclipse.search.internal.ui.SearchManager.handleNewSearchResult(SearchManager.java:391)
	at org.eclipse.search.internal.ui.SearchManager.access$2(SearchManager.java:387)
	at org.eclipse.search.internal.ui.SearchManager$6.run(SearchManager.java:331)
	at org.eclipse.ui.internal.UILockListener.doPendingWork(UILockListener.java:150)
	at org.eclipse.ui.internal.UISynchronizer$1.run(UISynchronizer.java:36)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:118)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:2871)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2530)
	at
org.eclipse.jface.operation.ModalContext$ModalContextThread.block(ModalContext.java:153)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:303)
	at
org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:447)
	at
org.eclipse.search.internal.ui.util.ExtendedDialogWindow.run(ExtendedDialogWindow.java:193)
	at
com.intershop.enfinity.studio.core.common.BeehiveOperationManager.run(BeehiveOperationManager.java:139)
	at
com.intershop.enfinity.studio.core.common.BeehiveOperationManager.run(BeehiveOperationManager.java:256)
	at
com.intershop.enfinity.studio.core.search.CartridgeElementsSearchPage.performAction(CartridgeElementsSearchPage.java:403)
	at org.eclipse.search.internal.ui.SearchDialog.performAction(SearchDialog.java:366)
	at
org.eclipse.search.internal.ui.util.ExtendedDialogWindow.buttonPressed(ExtendedDialogWindow.java:159)
	at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:556)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2894)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2527)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:803)
	at org.eclipse.jface.window.Window.open(Window.java:781)
	at
org.eclipse.search.internal.ui.OpenSearchDialogAction.run(OpenSearchDialogAction.java:59)
	at
org.eclipse.search.internal.ui.OpenSearchDialogAction.run(OpenSearchDialogAction.java:46)
	at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:246)
	at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:220)
	at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:538)
	at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:488)
	at
org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:400)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2894)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2527)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1570)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1534)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:306)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
	at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:228)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:156)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:315)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:268)
	at org.eclipse.core.launcher.Main.run(Main.java:942)
	at org.eclipse.core.launcher.Main.main(Main.java:926)
Comment 1 Martin Aeschlimann CLA 2005-05-25 12:55:11 EDT
can you explain me how the SearchResultViewEntry.getAdapter can return an
element that is not compatible to the given adapter?
Comment 2 Stefan Holzknecht CLA 2005-05-26 01:44:57 EDT
(In reply to comment #1)
> can you explain me how the SearchResultViewEntry.getAdapter can return an
> element that is not compatible to the given adapter?

The entry uses the adapters of IResource as its own. That is the problem because
the adapter itself is intended as adapter of IResource but not of
SearchResultViewEntry. Imagine a workbench adapter that is created as adapter of
IResource. Its method IWorkbenchAdapter.getChildren(Object o) expect now
resources not search result entries.
Comment 3 Martin Aeschlimann CLA 2005-06-07 13:45:36 EDT
fixed > 20050607

You are right, forwarding an adaptable call is wrong. Removed this.
Comment 4 Dani Megert CLA 2005-06-10 04:21:42 EDT
verifying
Comment 5 Dani Megert CLA 2005-06-10 05:01:00 EDT
cannot verify.
Comment 6 Dani Megert CLA 2005-06-10 05:17:25 EDT
Read the spec again and talked to Dirk:
The problem is that the adapter for X expects that it is an adapter for X and
hence it is
- OK that the adapter does the hard cast
- not OK to delegate getAdapter to another type

Verified in code of I20050610-0010.