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

Bug 36876

Summary: CView makes ClassCastException when exiting workbench
Product: [Tools] CDT Reporter: Martin Lescuyer <mlescuyer>
Component: cdt-coreAssignee: Alain Magloire <alain>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 2.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Martin Lescuyer CLA 2003-04-25 04:06:46 EDT
Hi,

In method org.eclipse.cdt.internal.ui.cview.CView.saveState(IMemento), called 
when exiting the workbench, line 1284, the selected elements of the tree viewer 
is systematically casted into ICElement, which causes an exception if for 
example, an a.txt file is selected. 

Object elements[] = ((IStructuredSelection)viewer.getSelection()).toArray();
 if(elements.length > 0) {
  IMemento selectionMem = memento.createChild(TAG_SELECTION);
  for (int i = 0; i < elements.length; i++) {
    ICElement e  = (ICElement)elements[i]; // ClassCastException !!!

It looks to me that a test with instanceof before casting would be required, 
although I do not catch everything what is made there and so, do not know what 
to do in the else branch.

Thanks in advance
Martin
Comment 1 Alain Magloire CLA 2003-04-25 17:15:07 EDT
You are right.
This is a bug, Will fix this.
Busy now will get back to you. Sorry for the delays.
Comment 2 Alain Magloire CLA 2003-04-26 20:19:44 EDT
Nice cath, martin.  It is fix in the cvs head.
Will close this PR once the patch is move in the cdt_1_1 branch.

Thanks
Comment 3 Alain Magloire CLA 2003-04-29 15:04:24 EDT
Fix in head and CDT_1_1

Pr Fixed

Thanks