Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 346805 - Object is not detached from it's resource on unload
Summary: Object is not detached from it's resource on unload
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: Core (show other bugs)
Version: 2.6.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ed Merks CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 390022
  Show dependency tree
 
Reported: 2011-05-22 04:10 EDT by Rimvydas CLA
Modified: 2012-09-21 04:44 EDT (History)
2 users (show)

See Also:


Attachments
unit test (16.09 KB, application/zip)
2011-05-22 04:12 EDT, Rimvydas CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rimvydas CLA 2011-05-22 04:10:51 EDT
Build Identifier: 20110218-0911

Object folderA is added into contents of resourceA and object folderB is added into contents of resourceB. folderA contains folderB. Unload of resourceB causes that folderB will be attached to resourceA but it was not detached from resourceB.

Expected: folderB should be:
1. detached from resourceB
2. attached to resourceA

Reproducible: Always

Steps to Reproduce:
1. Run attached unit test
Comment 1 Rimvydas CLA 2011-05-22 04:12:02 EDT
Created attachment 196289 [details]
unit test
Comment 2 Ed Merks CLA 2011-11-28 06:35:06 EST
The fix is committed to CVS for EMF 2.8.
Comment 3 Ed Merks CLA 2012-01-09 04:00:16 EST
The fix is available in a build.
Comment 4 Andreas Muelder CLA 2012-09-20 10:40:35 EDT
It seems that this bug fix causes regression to GMF
see Bug #390022
Comment 5 Ed Merks CLA 2012-09-21 00:37:26 EDT
Yes, GMF is calling internal APIs inappropriately.  That method says

  /**
   * Sets this object to be directly contained by the resource 
   * and returns accumulated notifications.
   * This is only done as the inverse of {@link Resource#getContents()}<code>.add(this)</code>.
   * @return accumulated notifications.
   */
  NotificationChain eSetResource(Resource.Internal resource, NotificationChain notifications);

I.e., it's only called as part of bidirectional handshaking.  Calling it directly will leave things in an inconsistent state.  I.e., the other half of the bidirectional isn't updated.


In a newsgroup posting in July I suggested:

The GMF code should be using resource.getContents().remove(...).   I.e., perhaps it should be referencedObject.eResource().getContents().remove(referencedObject) though I'm not sure if the referenced object is necessarily contained directly in a resource so maybe it should check that eResource() isn't null. 

You should open a bugzilla for the GMF runtime to fix this.
Comment 6 Andreas Muelder CLA 2012-09-21 04:39:50 EDT
Thanks for clarification, your suggestion works very well.
I provided a patch for the GMF bug.