summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2010-09-12 22:09:40 (EDT)
committerCaspar De Groot2010-09-12 22:09:40 (EDT)
commit51739dba02253c70c474a5556d5718548141d043 (patch)
tree22429592e70e9fe425454825c4b53643e0e3faea
parent741df3c432dd44d7d6fa50ac99adef4de9f97c28 (diff)
downloadcdo-51739dba02253c70c474a5556d5718548141d043.zip
cdo-51739dba02253c70c474a5556d5718548141d043.tar.gz
cdo-51739dba02253c70c474a5556d5718548141d043.tar.bz2
[324756] NPE in TransactionCommitContext with re-attached object on branch.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=324756
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_324756_Test.java139
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java2
3 files changed, 142 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
index eba5221..cb5873d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
@@ -93,6 +93,7 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_322804_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_323930_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_323958_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_324084_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_324756_Test;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
@@ -250,6 +251,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_323930_Test.class);
testClasses.add(Bugzilla_323958_Test.class);
testClasses.add(Bugzilla_324084_Test.class);
+ testClasses.add(Bugzilla_324756_Test.class);
// TODO testClasses.add(NonCDOResourceTest.class);
// TODO testClasses.add(GeneratedEcoreTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_324756_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_324756_Test.java
new file mode 100644
index 0000000..beb2aa4
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_324756_Test.java
@@ -0,0 +1,139 @@
+/**
+ * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Pascal Lehmann - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model4.ContainedElementNoOpposite;
+import org.eclipse.emf.cdo.tests.model4.MultiContainedElement;
+import org.eclipse.emf.cdo.tests.model4.RefMultiContained;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.view.CDOAdapterPolicy;
+
+/**
+ * NPE in TransactionCommitContext with re-attached object on branch.
+ * <p>
+ * See bug 324756
+ *
+ * @author Pascal Lehmann
+ */
+public class Bugzilla_324756_Test extends AbstractCDOTest
+{
+ public void testReattachBranchVersion() throws Exception
+ {
+ skipUnlessBranching();
+
+ // setup transaction.
+ final CDOSession session1 = openSession();
+ final CDOTransaction s1Tr1 = session1.openTransaction();
+ s1Tr1.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
+
+ // create resource, container using transaction 1.
+ final CDOResource resource = s1Tr1.createResource("/test1");
+ RefMultiContained container = getModel4Factory().createRefMultiContained();
+ resource.getContents().add(container);
+
+ s1Tr1.commit();
+
+ // do a couple of changes to have the version increase.
+ MultiContainedElement element1 = getModel4Factory().createMultiContainedElement();
+ container.getElements().add(element1);
+
+ s1Tr1.commit();
+
+ container.getElements().remove(0);
+
+ s1Tr1.commit();
+
+ // setup another branch.
+ final CDOBranch otherBranch = s1Tr1.getBranch().createBranch("other");
+ final CDOTransaction s1Tr3 = session1.openTransaction(otherBranch);
+
+ CDOResource branchResource = s1Tr3.getObject(resource);
+ assertNotSame(null, branchResource);
+
+ // detach container on branch.
+ RefMultiContained otherContainer = (RefMultiContained)branchResource.getContents().remove(0);
+ assertNotSame(null, otherContainer);
+
+ // re-attach container.
+
+ branchResource.getContents().add(otherContainer);
+
+ s1Tr3.commit(); // <--- This will store the revision with the wrong version.
+
+ // do a change to create a RevisionDelta with wrong version.
+ MultiContainedElement element2 = getModel4Factory().createMultiContainedElement();
+ otherContainer.getElements().add(element2);
+
+ s1Tr3.commit(); // <--- This will throw the exception:
+ // java.lang.NullPointerException at
+ // org.eclipse.emf.cdo.internal.server.TransactionCommitContext.isContainerLocked(TransactionCommitContext.java:712)
+
+ assertEquals(false, s1Tr3.isDirty());
+ }
+
+ public void testReattachBranchVersion2() throws Exception
+ {
+ skipUnlessBranching();
+
+ // setup transaction.
+ final CDOSession session1 = openSession();
+ final CDOTransaction s1Tr1 = session1.openTransaction();
+ s1Tr1.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
+
+ // create resource, element using transaction 1.
+ final CDOResource resource = s1Tr1.createResource("/test1");
+ ContainedElementNoOpposite element = getModel4Factory().createContainedElementNoOpposite();
+ element.setName("Version1");
+ resource.getContents().add(element);
+
+ s1Tr1.commit();
+
+ // do a couple of changes to have the version increase.
+ element.setName("Version2");
+
+ s1Tr1.commit();
+
+ element.setName("Version3");
+
+ s1Tr1.commit();
+
+ // setup another branch.
+ final CDOBranch otherBranch = s1Tr1.getBranch().createBranch("other");
+ final CDOTransaction s1Tr3 = session1.openTransaction(otherBranch);
+
+ CDOResource branchResource = s1Tr3.getObject(resource);
+ assertNotSame(null, branchResource);
+
+ // detach container on branch.
+ ContainedElementNoOpposite otherElement = (ContainedElementNoOpposite)branchResource.getContents().remove(0);
+ assertNotSame(null, otherElement);
+
+ // re-attach container.
+
+ branchResource.getContents().add(otherElement);
+
+ s1Tr3.commit(); // <--- This will store the revision with the wrong version.
+
+ // do a change to create a RevisionDelta with wrong version.
+ otherElement.setName("BranchVersion2");
+
+ s1Tr3.commit(); // <--- This will throw the exception:
+ // java.lang.IllegalStateException: Origin revision not found for
+ // CDORevisionDelta[ContainedElementNoOpposite@OID2:1v4 --> [CDOFeatureDelta[name, SET, value=BranchVersion2]]]
+
+ assertEquals(false, s1Tr3.isDirty());
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
index 40dd6ee..805c175 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
@@ -690,7 +690,7 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
CDORevisionFactory factory = revisionManager.getFactory();
InternalCDORevision revision = (InternalCDORevision)factory.createRevision(object.eClass());
revision.setID(id);
- revision.setBranchPoint(transaction.getBranch().getHead());
+ revision.setBranchPoint(revKey.getBranch().getHead());
revision.setVersion(revKey.getVersion());
// Populate the revision based on the values in the CDOObject