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

Bug 345195

Summary: SavingEMFResource casts to XMLResource to obtain the EObject ID without checking the resource type first
Product: [Modeling] GMF-Runtime Reporter: Wayne <wdiu>
Component: GeneralAssignee: Aurelien Pupier <apupier>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ahunter.eclipse, apupier
Version: unspecifiedFlags: apupier: review+
Target Milestone: 1.5.1   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Patch to resolve the problem
none
Patch to resolve the problem
none
Patch using Genericity ahunter.eclipse: iplog+

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