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

Bug 320855

Summary: [Legacy] Legacy fails when loading a contained object before its container
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    
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Patch V1 none

Description Martin Fluegge CLA 2010-07-25 15:54:58 EDT
Cloned from: 320837: [Legacy] Legacy fails when loading a contained object before its container
https://bugs.eclipse.org/bugs/show_bug.cgi?id=320837

When loading a contained object before is container legacy crashes with the following exception:


java.lang.IllegalStateException: Failing event PREPARE in state CLEAN for CDOLegacyWrapper[OID3, org.eclipse.emf.cdo.tests.legacy.model4.impl.ContainedElementNoOppositeImpl] (data=Pair[CDOTransaction[3:1], []])
	at org.eclipse.net4j.util.fsm.FiniteStateMachine.process(FiniteStateMachine.java:153)
	at org.eclipse.emf.internal.cdo.CDOStateMachine.prepare(CDOStateMachine.java:229)
	at org.eclipse.emf.internal.cdo.CDOStateMachine.attach(CDOStateMachine.java:191)
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.attached(CDOResourceImpl.java:827)
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.attached(CDOResourceImpl.java:818)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eBasicSetContainer(BasicEObjectImpl.java:1342)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eInverseAdd(BasicEObjectImpl.java:1423)
	at org.eclipse.emf.cdo.tests.legacy.model4.impl.RefSingleContainedNPLImpl.setElement(RefSingleContainedNPLImpl.java:121)
	at org.eclipse.emf.cdo.tests.legacy.model4.impl.RefSingleContainedNPLImpl.eSet(RefSingleContainedNPLImpl.java:180)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1081)
	at org.eclipse.emf.internal.cdo.CDOLegacyWrapper.revisionToInstanceFeature(CDOLegacyWrapper.java:554)
	at org.eclipse.emf.internal.cdo.CDOLegacyWrapper.revisionToInstance(CDOLegacyWrapper.java:423)
	at org.eclipse.emf.internal.cdo.CDOLegacyWrapper.cdoInternalPostLoad(CDOLegacyWrapper.java:298)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.cleanObject(CDOViewImpl.java:1179)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.createObject(CDOViewImpl.java:1130)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.getObject(CDOViewImpl.java:1005)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.getObject(CDOTransactionImpl.java:878)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.getObject(CDOTransactionImpl.java:1)
	at org.eclipse.emf.internal.cdo.CDOLegacyWrapper.getEObjectFromPotentialID(CDOLegacyWrapper.java:796)
	at org.eclipse.emf.internal.cdo.CDOLegacyWrapper.revisionToInstanceContainment(CDOLegacyWrapper.java:456)
	at org.eclipse.emf.internal.cdo.CDOLegacyWrapper.revisionToInstance(CDOLegacyWrapper.java:419)
	at org.eclipse.emf.internal.cdo.CDOLegacyWrapper.cdoInternalPostLoad(CDOLegacyWrapper.java:298)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.cleanObject(CDOViewImpl.java:1179)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.createObject(CDOViewImpl.java:1130)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.getObject(CDOViewImpl.java:1005)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.getObject(CDOTransactionImpl.java:878)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.getObject(CDOViewImpl.java:1048)
	at org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_320690_Tests.testLockRefTargets(Bugzilla_320690_Tests.java:60)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:168)
	at org.eclipse.net4j.util.tests.AbstractOMTest.runBare(AbstractOMTest.java:150)
	at org.eclipse.emf.cdo.tests.config.impl.ConfigTest.runBare(ConfigTest.java:422)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:124)
	at org.eclipse.net4j.util.tests.AbstractOMTest.run(AbstractOMTest.java:196)
	at junit.framework.TestSuite.runTest(TestSuite.java:232)
	at org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite$TestWrapper.runTest(ConfigTestSuite.java:126)
	at junit.framework.TestSuite.run(TestSuite.java:227)
	at junit.framework.TestSuite.runTest(TestSuite.java:232)
	at junit.framework.TestSuite.run(TestSuite.java:227)
	at junit.framework.TestSuite.runTest(TestSuite.java:232)
	at junit.framework.TestSuite.run(TestSuite.java:227)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


I ran through the problem and it seems that the caus of the problem can be described as follows:

If the contained element is loaded, the wrapper will be created by CDO, set to state CLEAN and afterwards cdoInternalPostLoad() will be called which sets the information from the revision to the instance. 

Thereby the container of the element is set. This lead to a creation of the container object, which itself transforms the revision data to its instance. This leads to setting the contained object to its related feature in the container.

At this point the contained elements resource is null wherefore it will be attached to the containers resource (BasicEObjectImpl, 1342). This results in attaching the object to the CDOResource and processing an ATTACH operation in the CDOStateMachine. Remember that the contained object which should be attached to the resource it already in state CLEAN. So, the state machine denies preparing it. 

This does not happen if the container is loaded before, because the contained object will be created during the containers creation.
Comment 1 Martin Fluegge CLA 2010-07-25 16:07:55 EDT
Created attachment 175187 [details]
Patch V1

I created a patch for the maintenance branch. But to keep compatibility the  method instanceToRevisionContainment() is not renamed here. Eike, do you think this is o.k.?
Comment 2 Eike Stepper CLA 2010-07-26 02:23:04 EDT
CDOLegacyWrapper is an internal class. You can change it in any way. API Tooling should give you errors otherwise.
Comment 3 Martin Fluegge CLA 2010-07-26 02:39:17 EDT
Yes, that's why I was wondering. API Tooling complained that the method was removed (due to the renaming). Maybe the package is not declared internal anymore? I'll check this this evening.
Comment 4 Martin Fluegge CLA 2010-07-26 14:30:29 EDT
O.k. Found it. 

org.eclipse.emf.cdo.internal is not internal. Neither on HEAD nor on the 3.0 maintenance branch. It is visible to downstream plug-ins. I assume that this is a mistake. But I better ask. Maybe there is some reason for this ;)

I suggest fixing this and applying the patch from bug 320837 if nothing speaks against it.
Comment 5 Eike Stepper CLA 2010-07-27 02:24:46 EDT
(In reply to comment #4)
> O.k. Found it. 
> 
> org.eclipse.emf.cdo.internal is not internal. Neither on HEAD nor on the 3.0
> maintenance branch. It is visible to downstream plug-ins. I assume that this is
> a mistake. But I better ask. Maybe there is some reason for this ;)
> 
> I suggest fixing this and applying the patch from bug 320837 if nothing speaks
> against it.

I remember again why this package is not x-internal: It contains CDOObjectImpl, which has to be extended by generated model plugins ;-(

We can not make it x-internal. The "nicest" solution would be to move CDOObjectImpl to a public org.eclipse.emf.cdo.impl package (in analogy to org.eclipse.emf.ecore.impl.EObjectImpl) but that would break *everybody*.

We can only consider to move everything else out of the package org.eclipse.emf.cdo.internal, into packages that are really x-internal...
Comment 6 Eike Stepper CLA 2010-07-27 02:26:49 EDT
I'm reluctant to do big moves in general until we've migrated to git because with CVS we'd loose all history.
Comment 7 Martin Fluegge CLA 2010-07-27 02:41:20 EDT
Wouldn't do the move either yet. What about the following idea: 

We keep the patch as it is, which means that on HEAD the method is called *revisionToInstanceContainer()* and on 3.0.1 *revisionToInstanceContainment()*. Not nice, but I can keep that in mind.

After switching to git we clean up the 'internal' problem and I synchronize the method names. If you agree, shall I file a reminder bug for the package move? 

Another option would be that we postpone this bugzilla until after the git move. But this problem is likely to occur if a containment is read out before it's container...
Comment 8 Eike Stepper CLA 2010-07-27 02:50:51 EDT
(In reply to comment #7)
> Wouldn't do the move either yet. What about the following idea: 
> 
> We keep the patch as it is, which means that on HEAD the method is called
> *revisionToInstanceContainer()* and on 3.0.1 *revisionToInstanceContainment()*.
> Not nice, but I can keep that in mind.

Yes.

> After switching to git we clean up the 'internal' problem and I synchronize the
> method names. If you agree, shall I file a reminder bug for the package move? 

No, we don't clean up in maintenance ;-)
Comment 9 Martin Fluegge CLA 2010-07-27 07:29:17 EDT
Alright. Committed to R3_0_maintenance.
Comment 10 Eike Stepper CLA 2011-06-23 04:27:54 EDT
Moving all open problem reports to 4.0
Comment 11 Eike Stepper CLA 2012-09-21 06:37:06 EDT
Undoing accidental version change.
Comment 12 Eike Stepper CLA 2012-09-21 06:52:37 EDT
Closing.