Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 345195 - SavingEMFResource casts to XMLResource to obtain the EObject ID without checking the resource type first
Summary: SavingEMFResource casts to XMLResource to obtain the EObject ID without check...
Status: RESOLVED FIXED
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal
Target Milestone: 1.5.1   Edit
Assignee: Aurelien Pupier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-09 16:00 EDT by Wayne CLA
Modified: 2011-05-30 17:30 EDT (History)
2 users (show)

See Also:
apupier: review+


Attachments
Patch to resolve the problem (2.13 KB, patch)
2011-05-09 16:04 EDT, Wayne CLA
no flags Details | Diff
Patch to resolve the problem (2.23 KB, patch)
2011-05-10 11:33 EDT, Wayne CLA
no flags Details | Diff
Patch using Genericity (1.92 KB, patch)
2011-05-20 03:24 EDT, Aurelien Pupier CLA
ahunter.eclipse: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wayne CLA 2011-05-09 16:00:20 EDT
Build Identifier: org.eclipse.gmf.runtime.emf.clipboard.core_1.4.0.v20100430-1518.jar

org.eclipse.gmf.runtime.emf.clipboard.core.internal.SavingEMFResource casts to XMLResource to obtain the EObject ID without checking the resource type first.  This could result in a ClassCastException if the resource is not a XMLResource.

Reproducible: Always

Steps to Reproduce:
1. Load a resource that is not a subclass of XMLResource.
2. Attempt to copy the resource using org.eclipse.gmf.runtime.emf.clipboard.core.CopyOperation.doCopy().
3. Exception.
Comment 1 Wayne CLA 2011-05-09 16:04:05 EDT
Created attachment 195137 [details]
Patch to resolve the problem

The attached patch checks whether the resource is an instance of XMLResource before casting.  If not, it attempts to obtain the ID from the intrinsic ID to EObject map.  Although doing so may not be as efficient as using the default getID() implementation of XMLResource, the second way of obtaining the ID will only be used when the XMLResource is unavailable, which was previously throwing an exception.
Comment 2 Aurelien Pupier CLA 2011-05-09 21:31:01 EDT
Hi,

To improve performance in the case that it is not a XMLResource, we can use an EntrySet in order to avoid a search in the map.

Regards,
Comment 3 Wayne CLA 2011-05-10 11:33:42 EDT
Created attachment 195231 [details]
Patch to resolve the problem

Good point, Aurelien.  I've revised the patch.
Comment 4 Aurelien Pupier CLA 2011-05-20 03:24:27 EDT
Created attachment 196181 [details]
Patch using Genericity

Patch using genericity.
Please check that I correct it correctly and test it.

Thanks
Comment 5 Wayne CLA 2011-05-20 14:38:16 EDT
Looks good!
Comment 6 Aurelien Pupier CLA 2011-05-29 08:13:43 EDT
patch applied
Comment 7 Anthony Hunter CLA 2011-05-30 17:29:58 EDT
The patch we applied on 5/29 is not going to make it into indigo 1.5.0 GA.

We are following http://wiki.eclipse.org/Modeling_Project_Ramp_Down_Policy/Galileo

This missed the IP Log, committer and PMC approvals

This automatically rolls over the 1.5.1