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

Bug 110413

Summary: ClassCastException when accessing included features
Product: [Eclipse Project] Platform Reporter: DJ Houghton <dj.houghton>
Component: Update (deprecated - use Eclipse>Equinox>p2)Assignee: Branko Tripkovic <btripkov>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: francois, Mike_Wilson, nalinig, pombredanne, wassim.melhem, william_mills
Version: 3.2   
Target Milestone: 3.2 RC4   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 140942    
Attachments:
Description Flags
sample plug-in
none
patch to apply on FeatureModel.java none

Description DJ Houghton CLA 2005-09-23 06:49:30 EDT
build i0921

I talked to Branko briefly about this but thought I should enter a bug report. I
create an input stream on a feature.xml file and parse it with:
  FeatureModel feature = new FeatureModelFactory().parse(input)

Then I call:
  feature.getFeatureIncluded();

This gives me a ClassCastException. 

After doing a little debugging, I have determined that if the feature has only
<includes...> elements you get the error. If your feature has only <requires...>
elements then it is ok.

I will attach a sample plug-in. The included feature.xml files are copied from
the SDK. (JDT and Platform.Source)

 java.lang.ClassCastException:
[Lorg.eclipse.update.core.model.IncludedFeatureReferenceModel;
at
org.eclipse.update.core.model.FeatureModel.getFeatureIncluded(FeatureModel.java:410)
at test.feature.parse.actions.SampleAction.parse(SampleAction.java:55)
at test.feature.parse.actions.SampleAction.run(SampleAction.java:33)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:246)
at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:223)
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$6.handleEvent(ActionContributionItem.java:441)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:843)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3080)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2713)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1699)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:367)
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:226)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
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:334)
at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
at org.eclipse.core.launcher.Main.run(Main.java:973)
at org.eclipse.core.launcher.Main.main(Main.java:948)
Comment 1 DJ Houghton CLA 2005-09-23 06:52:22 EDT
Created attachment 27426 [details]
sample plug-in

Here is a sample plug-in. It is based off the HelloWorld sample plug-in project
so just hit the icon to start it. 

It will first try to parse the OK feature. Then it will try and parse the ERROR
feature. It will display a message dialog after each. Exception stack traces
are printed to System.err.
Comment 2 Nalini Ganapati CLA 2006-03-17 14:42:31 EST
I have encountered this bug as well. I need a fix for the ClassCastException that gets thrown while invoking getFeatureIncluded() urgently and was wondering if the priority/severity can be bumped up.
Comment 3 Pascal Rapicault CLA 2006-03-17 14:47:34 EST
we are already under pressure, providing a patch would be more really great.
Comment 4 Branko Tripkovic CLA 2006-05-09 17:36:39 EDT
Created attachment 40884 [details]
patch to apply on FeatureModel.java
Comment 5 Dejan Glozic CLA 2006-05-09 17:40:06 EDT
Wassim, Mike, we need +1 for this problem. In addition to being trivial to fix, it blocks bug 140942.
Comment 6 Dejan Glozic CLA 2006-05-09 17:41:46 EDT
For bug approvers: the current code erroniously adds a feature object to the list of included features. The code later expects to get included feature reference and fails in class cast. The fix is to add a feature reference using the suitable constructor.
Comment 7 Mike Wilson CLA 2006-05-09 18:20:41 EDT
Thanks for the extra info, since the patch did not provide enough context for me to understand the nature of the problem.

+1.
Comment 8 Wassim Melhem CLA 2006-05-09 18:52:12 EDT
+1
Comment 9 Dejan Glozic CLA 2006-05-11 10:30:45 EDT
Released as part of bug 140942.
Comment 10 Branko Tripkovic CLA 2006-06-23 13:31:38 EDT
*** Bug 58367 has been marked as a duplicate of this bug. ***