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

Bug 318518

Summary: [Legacy] CDOLegacy Wrapper should not set opposite references when detaching bi-directional references
Product: [Modeling] EMF Reporter: Martin Fluegge <martin.fluegge>
Component: cdo.legacyAssignee: Martin Fluegge <martin.fluegge>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3 Flags: stepper: review+
Version: 4.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Patch v1
none
Test v1
none
Patch v2
none
Test v2 none

Description Martin Fluegge CLA 2010-06-30 15:14:53 EDT
When an object is remove from an bi-drectional reference (e.g a TaskImpl from the tasks list of a TaskContainer) EMF performs a basicSetContainer which in the and leads to a detach of the object (cdoInternalPostDetach(boolean)). Here the container is set which result in a CDO delta for the set operation. This should not occur here. 

See the stack trace below as reminder:

org.eclipse.emf.internal.cdo.CDOStore.set(org.eclipse.emf.ecore.InternalEObject, org.eclipse.emf.ecore.EStructuralFeature, int, java.lang.Object) line: 336 
 org.eclipse.emf.internal.cdo.CDOLegacyAdapter(org.eclipse.emf.internal.cdo.CDOLegacyWrapper).setOppositeReference(org.eclipse.emf.internal.cdo.CDOObjectWrapper, org.eclipse.emf.ecore.EReference) line: 232 
 org.eclipse.emf.internal.cdo.CDOLegacyAdapter(org.eclipse.emf.internal.cdo.CDOLegacyWrapper).cdoInternalPostDetach(boolean) line: 215 
 org.eclipse.emf.internal.cdo.CDOStateMachine.detach(org.eclipse.emf.spi.cdo.InternalCDOObject) line: 278 
 org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.detached(org.eclipse.emf.ecore.EObject) line: 838 
 org.eclipse.emf.cdo.tests.legacy.model2.impl.TaskImpl(org.eclipse.emf.ecore.impl.BasicEObjectImpl).eBasicSetContainer(org.eclipse.emf.ecore.InternalEObject, int, org.eclipse.emf.common.notify.NotificationChain) line: 1334 
 org.eclipse.emf.cdo.tests.legacy.model2.impl.TaskImpl.basicSetTaskContainer(org.eclipse.emf.cdo.tests.model2.TaskContainer, org.eclipse.emf.common.notify.NotificationChain) line: 118 
 org.eclipse.emf.cdo.tests.legacy.model2.impl.TaskImpl.eInverseRemove(org.eclipse.emf.ecore.InternalEObject, int, org.eclipse.emf.common.notify.NotificationChain) line: 225 
 org.eclipse.emf.cdo.tests.legacy.model2.impl.TaskImpl(org.eclipse.emf.ecore.impl.BasicEObjectImpl).eInverseRemove(org.eclipse.emf.ecore.InternalEObject, int, java.lang.Class<?>, org.eclipse.emf.common.notify.NotificationChain) line: 1447 
 org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList<E>(org.eclipse.emf.ecore.util.EcoreEList<E>).inverseRemove(E, org.eclipse.emf.common.notify.NotificationChain) line: 318 
 org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList<E>(org.eclipse.emf.common.notify.impl.NotifyingListImpl<E>).remove(int) line: 716 
 org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_316887_Test.testResolveConflictWithAdjustedNotifcations() line: 101 
 sun.reflect.NativeMethodAccessorImpl.invoke0(java.lang.reflect.Method, java.lang.Object, java.lang.Object[]) line: not available [native method] 
 sun.reflect.NativeMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: 39 
 sun.reflect.DelegatingMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: 25 
 java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object...) line: 592 
 org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_316887_Test(junit.framework.TestCase).runTest() line: 168 
 org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_316887_Test(org.eclipse.net4j.util.tests.AbstractOMTest).runBare() line: 145 
 org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_316887_Test(org.eclipse.emf.cdo.tests.config.impl.ConfigTest).runBare() line: 422 
 junit.framework.TestResult$1.protect() line: 110 
 junit.framework.TestResult.runProtected(junit.framework.Test, junit.framework.Protectable) line: 128 
 junit.framework.TestResult.run(junit.framework.TestCase) line: 113 
 org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_316887_Test(junit.framework.TestCase).run(junit.framework.TestResult) line: 124 
 org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_316887_Test(org.eclipse.net4j.util.tests.AbstractOMTest).run(junit.framework.TestResult) line: 191 
 junit.framework.TestSuite.runTest(junit.framework.Test, junit.framework.TestResult) line: 232 
 junit.framework.TestSuite.run(junit.framework.TestResult) line: 227 
 org.junit.internal.runners.JUnit38ClassRunner.run(org.junit.runner.notification.RunNotifier) line: 83 
 org.eclipse.jdt.internal.junit4.runner.JUnit4TestMethodReference(org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference).run(org.eclipse.jdt.internal.junit.runner.TestExecution) line: 49 
 org.eclipse.jdt.internal.junit.runner.TestExecution.run(org.eclipse.jdt.internal.junit.runner.ITestReference[]) line: 38 
 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(java.lang.String[], java.lang.String, org.eclipse.jdt.internal.junit.runner.TestExecution) line: 467 
 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(org.eclipse.jdt.internal.junit.runner.TestExecution) line: 683 
 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run() line: 390 
 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(java.lang.String[]) line:
Comment 1 Martin Fluegge CLA 2010-06-30 15:25:56 EDT
Created attachment 173150 [details]
Patch v1

This one solves the problem but leads to some trouble in the testcases for bug 251263. As far as I remember I introduced the oppsite alignment in the post detach because legacy failures in the test case. So the patch is just a reminder for me.
Comment 2 Martin Fluegge CLA 2010-07-02 06:42:55 EDT
Created attachment 173288 [details]
Test v1

Here is a patch to validate the problem.
Comment 3 Martin Fluegge CLA 2010-07-02 11:16:50 EDT
Created attachment 173311 [details]
Patch v2

In the end the problem was pretty easy to solve. I simply must not handle containment references when calling cdoInternalPostDetach(). 

As a side note: This patch also fixes the problems in  Bug 318347, though the test logic of this bug is still questionable.
Comment 4 Martin Fluegge CLA 2010-07-02 11:17:24 EDT
Created attachment 173312 [details]
Test v2

Here's a test to validate the patch.
Comment 5 Martin Fluegge CLA 2010-07-03 07:04:14 EDT
Committed to HEAD.
Comment 6 Eike Stepper CLA 2011-06-23 03:41:30 EDT
Available in R20110608-1407