Bug 186787 - instanceof checks in model builder causes template parameters to be lost in template declarations
Summary: instanceof checks in model builder causes template parameters to be lost in t...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.3   Edit
Assignee: Chris Recoskie CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-05-14 09:58 EDT by Jason Montojo CLA
Modified: 2008-06-19 23:49 EDT (History)
2 users (show)

See Also:


Attachments
Proposed patch (1.99 KB, patch)
2007-05-14 12:40 EDT, Jason Montojo CLA
bjorn.freeman-benson: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Montojo CLA 2007-05-14 09:58:55 EDT
In CModelBuilder, there are a few blocks of code like this which handle template parameters:

...
} else if (element instanceof StructureTemplate) {
    // set the template parameters				
    StructureTemplateDeclaration classTemplate = (StructureTemplateDeclaration) element;
    classTemplate.setTemplateParameterTypes(parameterTypes);				
}
...

The problem here is that an instanceof check is done for StructureTemplate, but the object is casted to StructureTemplateDeclaration, which isn't in a subclass of StructureTemplate.

I'll post a patch shortly.
Comment 1 Jason Montojo CLA 2007-05-14 11:27:49 EDT
This branch actually never gets executed because the overall structure looks like this:

if (element instanceof StructureTemplate) {
    StructureTemplate template = (StructureTemplate) element;
    ...
} else if (element instanceof StructureTemplate) {
    StructureTemplateDeclaration template = (StructureTemplateDeclaration) element;
   ...
}

So the danger here isn't a potential ClassCastException.  It just drops template parameters for template declarations in the model.
Comment 2 Jason Montojo CLA 2007-05-14 12:40:18 EDT
Created attachment 67096 [details]
Proposed patch

This patch fixes the instanceof checks so that template parameters get set on StructureTemplateDeclarations.
Comment 3 Chris Recoskie CLA 2007-05-14 14:43:03 EDT
Applied to the cdt_3_1 branch.  Thanks Jay.
Comment 4 Chris Recoskie CLA 2007-05-14 14:44:44 EDT
Janees please verify.