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

Bug 324084

Summary: CommitException with XRef on new objects after branch merge
Product: [Modeling] EMF Reporter: Pascal Lehmann <pascal.lehmann>
Component: cdo.coreAssignee: Eike Stepper <stepper>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3    
Version: 4.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: offline-01
Attachments:
Description Flags
Testcase
stepper: iplog+
Proposed patch stepper: iplog+

Description Pascal Lehmann CLA 2010-08-31 09:03:03 EDT
Build Identifier: 4.0

Commit will throw a CommitException for new objects which have been merged from another branch when XRef-check is enabled, because the objects are not excluded from the lockTargets list:

Caused by: java.lang.IllegalStateException: Object OID4 can not be referenced anymore because it has been detached
	at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.lockObjects(TransactionCommitContext.java:662)
	at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.write(TransactionCommitContext.java:318)
	at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:39)
	at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:1)
	at org.eclipse.net4j.util.om.monitor.ProgressDistributor.run(ProgressDistributor.java:96)

Reproducible: Always

Steps to Reproduce:
1. setup environment with XRef checking and 2 branches.
2. create a new (single or many value) containment object and add it to one branch.
3. merge it to the other branch, then commit.
Comment 1 Pascal Lehmann CLA 2010-08-31 09:05:52 EDT
Created attachment 177831 [details]
Testcase
Comment 2 Pascal Lehmann CLA 2010-08-31 09:07:31 EDT
Created attachment 177832 [details]
Proposed patch

I added a check of the newObjects list before adding the object to the lockTargets.
Comment 3 Pascal Lehmann CLA 2010-08-31 09:08:22 EDT
1) The number of lines that you changed is smaller than 250.
confirmed.
2) You are the only author of these changed lines.
confirmed.
3) You apply the EPL to these changed lines.
confirmed.
Comment 4 Eike Stepper CLA 2010-09-01 11:44:05 EDT
Good catch!

I've only changed it slightly in that the new check is done against a Set<CDOID> that is precalculated in lockObject():

      if (ensuringReferentialIntegrity)
      {
        final Set<CDOID> newIDs = new HashSet<CDOID>();
        for (int i = 0; i < newObjects.length; i++)
        {
          InternalCDORevision newRevision = newObjects[i];
          CDOID newID = newRevision.getID();
          if (newID instanceof CDOIDObject)
          {
            // After merges newObjects may contain non-TEMP ids
            newIDs.add(newID);
          }
        }
Comment 5 Eike Stepper CLA 2010-09-01 11:56:38 EDT
Committed to HEAD
Comment 6 Eike Stepper CLA 2011-06-23 03:39:01 EDT
Available in R20110608-1407