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

Bug 353493

Summary: Dynamic EObject is not removed from resource if added to another containment reference.
Product: [Modeling] EMF Reporter: sth2000 <sth2000>
Component: CoreAssignee: Ed Merks <Ed.Merks>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 2.7.0   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
JUnit test plugin, which tests the mentioned bug. none

Description sth2000 CLA 2011-08-01 09:04:26 EDT
Created attachment 200653 [details]
JUnit test plugin, which tests the mentioned bug.

I have the following situation: A car object is contained in one resource, a wheel object in another. The car has a containment reference for wheels. When the wheel is added to the car's wheels reference, the wheel should be removed from its containing resource, obviously. This works if I use generated code. It does not work with dynamic EObjects. The following JUnit plugin test case makes this more clear:

ResourceSet rs = new ResourceSetImpl();
Resource r1 = rs.createResource(URI.createURI("r1"));
Resource r2 = rs.createResource(URI.createURI("r2"));

Resource mmr = rs.getResource(				URI.createPlatformPluginURI("/emfTest/models/carExample.ecore", true), true);

EPackage ePackage = (EPackage) mmr.getContents().get(0);
EClass carEClass = (EClass) ePackage.getEClassifier("Car");
EClass wheelEClass = (EClass) ePackage.getEClassifier("Wheel");

/*
 * Create a car and add it to r1
 */
EObject car = ePackage.getEFactoryInstance().create(carEClass);
r1.getContents().add(car);

/*
 * create a wheel and add it to r2
 */
EObject wheel = ePackage.getEFactoryInstance().create(wheelEClass);
r2.getContents().add(wheel);

/*
 * Now, add the wheel to the car's wheels reference, which is a containment reference
 */
((EList<EObject>) car.eGet(carEClass.getEStructuralFeature("wheels"))).add(wheel);

/*
 * Now, the wheel should not be a root element of r2.
 * This assertions fails in case of dynamic EObjects.
 */
assertTrue(!r2.getContents().contains(wheel));


I have attached this code as a JUnit test plugin, which also includes the carExample.ecore file.
Comment 1 Ed Merks CLA 2011-08-01 16:16:30 EDT
This is how proxy resolving containment references are supposed to work.  If you want the behavior you're expecting, you'll need to set resolveProxies to false.