Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2020-05-27 07:32:15 +0000
committerEike Stepper2020-05-27 07:32:15 +0000
commita04528ec9ce299a2fc5b8c664de1e34b5a2be527 (patch)
tree24e3f19e0f622b0704e950cca6b95aab7470412c
parentec70f5640902d2f957b70a3b7df4be6ef8a49d8b (diff)
downloadcdo-a04528ec9ce299a2fc5b8c664de1e34b5a2be527.tar.gz
cdo-a04528ec9ce299a2fc5b8c664de1e34b5a2be527.tar.xz
cdo-a04528ec9ce299a2fc5b8c664de1e34b5a2be527.zip
[563616] DanglingReferenceException for unresolved EMF proxies at commit time
https://bugs.eclipse.org/bugs/show_bug.cgi?id=563616
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_563616_Test.java81
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java17
2 files changed, 98 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_563616_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_563616_Test.java
new file mode 100644
index 0000000000..41d5603ad6
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_563616_Test.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2020 Eike Stepper (Loehne, 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+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.model1.Customer;
+import org.eclipse.emf.cdo.tests.model1.Model1Package;
+import org.eclipse.emf.cdo.tests.model1.SalesOrder;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+
+/**
+ * Bug 563616 - DanglingReferenceException for unresolved EMF proxies at commit time.
+ *
+ * @author Eike Stepper
+ */
+public class Bugzilla_563616_Test extends AbstractCDOTest
+{
+ public void testImportProxyObject() throws Exception
+ {
+ // Create model.
+ Customer customer = getModel1Factory().createCustomer();
+
+ SalesOrder order = getModel1Factory().createSalesOrder();
+ order.setCustomer(customer);
+
+ // Create resources.
+ ResourceSet resourceSet = createResourceSet();
+
+ URI customerURI = URI.createFileURI(getTempName("test-customer-", ".xmi").getAbsolutePath());
+ Resource customerResource = resourceSet.createResource(customerURI);
+ customerResource.getContents().add(customer);
+
+ URI orderURI = URI.createFileURI(getTempName("test-order-", ".xmi").getAbsolutePath());
+ Resource orderResource = resourceSet.createResource(orderURI);
+ orderResource.getContents().add(order);
+
+ customerResource.save(null);
+ orderResource.save(null);
+
+ // Load order resource.
+ resourceSet = createResourceSet();
+ orderResource = resourceSet.getResource(orderURI, true);
+ order = (SalesOrder)orderResource.getContents().get(0);
+
+ // Assert that the customer is a proxy.
+ InternalEObject proxy = (InternalEObject)order.eGet(Model1Package.eINSTANCE.getSalesOrder_Customer(), false);
+ assertTrue(proxy.eProxyURI() != null);
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource cdoResource = transaction.createResource(getResourcePath("order"));
+ cdoResource.getContents().add(order);
+
+ // A DanglingReferenceException is thrown from AbstractCDOView.provideCDOID() if the proxy is not resolved.
+ transaction.commit();
+ }
+
+ private ResourceSet createResourceSet()
+ {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
+ return resourceSet;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
index 84e8f99343..40b04d970b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
@@ -2152,6 +2152,23 @@ public abstract class AbstractCDOView extends CDOCommitHistoryProviderImpl<CDOOb
return CDOIDUtil.createExternal(uri);
}
}
+ else
+ {
+ URI proxyURI = eObject.eProxyURI();
+ if (proxyURI != null)
+ {
+ ResourceSet resourceSet = getResourceSet();
+ EObject resolvedObject = EcoreUtil.resolve(eObject, resourceSet);
+ if (resolvedObject == eObject)
+ {
+ // The proxy could NOT be resolved.
+ return CDOIDUtil.createExternal(proxyURI.toString());
+ }
+
+ // The proxy was resolved. Call this method again with the resolved object.
+ return provideCDOID(resolvedObject);
+ }
+ }
throw new DanglingReferenceException(eObject);
}

Back to the top