Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2014-03-08 06:51:45 -0500
committerEike Stepper2014-03-08 06:55:57 -0500
commite0a0efe926e070f4399ff99c883a57c3f1800ab6 (patch)
treea663738fa50047614ea20d384a64029f6f3e1dbb
parent4e59121792b693f3a2cf9070b9b111db71ee1285 (diff)
downloadcdo-bugs/426463.tar.gz
cdo-bugs/426463.tar.xz
cdo-bugs/426463.zip
[426463] ArrayIndexOutOfBoundsException on rollback due to contains optimization in DelegatingEcoreEList bugs/426463
https://bugs.eclipse.org/bugs/show_bug.cgi?id=426463 Change-Id: I31911568d456d8d1900a98b48ad8bcb21698cf09 Signed-off-by: Eike Stepper <stepper@esc-net.de>
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_426463_Test.java127
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java59
2 files changed, 185 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_426463_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_426463_Test.java
new file mode 100644
index 0000000000..7b6ef36f96
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_426463_Test.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2014 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:
+ * Martin Platter, Bestsolution.at - 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.Company;
+import org.eclipse.emf.cdo.tests.model1.Customer;
+import org.eclipse.emf.cdo.tests.model1.SalesOrder;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.common.util.EList;
+
+/**
+ * Bug 426463 - ArrayIndexOutOfBoundsException on rollback due to contains optimization in DelegatingEcoreEList
+ *
+ * @author Martin Platter, Bestsolution.at
+ */
+public class Bugzilla_426463_Test extends AbstractCDOTest
+{
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ disableConsole();
+ super.doSetUp();
+ }
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ enableConsole();
+ super.doTearDown();
+ }
+
+ public void testRollback() throws Exception
+ {
+ msg("Opening session");
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/res1"));
+
+ msg("Create test customer");
+ Company company = getModel1Factory().createCompany();
+ Customer customer = getModel1Factory().createCustomer();
+ EList<SalesOrder> customerOrders = customer.getSalesOrders();
+
+ // We must add at least 5
+ for (int i = 1; i <= 5; i++)
+ {
+ SalesOrder createSalesOrder = getModel1Factory().createSalesOrder();
+ company.getSalesOrders().add(createSalesOrder);
+ customerOrders.add(createSalesOrder);
+ }
+
+ company.getCustomers().add(customer);
+ resource.getContents().add(company);
+ transaction.commit();
+
+ msg("Create test sales order and add to customer sales list");
+ SalesOrder salesOrder = getModel1Factory().createSalesOrder();
+ company.getSalesOrders().add(salesOrder);
+ customerOrders.add(salesOrder);
+
+ msg("Rollback");
+ transaction.rollback();
+
+ // Shouldn't fail:
+ customerOrders.contains(salesOrder);
+ }
+
+ public void testRollbackWithAdapter() throws Exception
+ {
+ msg("Opening session");
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/res1"));
+
+ msg("Create test customer");
+ Company company = getModel1Factory().createCompany();
+ Customer customer = getModel1Factory().createCustomer();
+ final EList<SalesOrder> customerOrders = customer.getSalesOrders();
+
+ // We must add at least 5
+ for (int i = 1; i <= 5; i++)
+ {
+ SalesOrder createSalesOrder = getModel1Factory().createSalesOrder();
+ company.getSalesOrders().add(createSalesOrder);
+ customerOrders.add(createSalesOrder);
+ }
+
+ company.getCustomers().add(customer);
+ resource.getContents().add(company);
+ transaction.commit();
+
+ msg("Create test sales order and add to customer sales list");
+ final SalesOrder salesOrder = getModel1Factory().createSalesOrder();
+ company.getSalesOrders().add(salesOrder);
+ customerOrders.add(salesOrder);
+
+ msg("Add listener and rollback");
+ company.eAdapters().add(new AdapterImpl()
+ {
+ @Override
+ public void notifyChanged(Notification notification)
+ {
+ if (notification.getEventType() == Notification.REMOVE)
+ {
+ // Must not crash here on rollback
+ customerOrders.contains(salesOrder);
+ }
+ }
+ });
+
+ transaction.rollback();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
index 34aa637f6a..6e44c52ed3 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
@@ -1197,7 +1197,38 @@ public class CDOObjectImpl extends MinimalEStoreEObjectImpl implements InternalC
return createUnorderedList(eStructuralFeature);
}
- return super.createList(eStructuralFeature);
+ return new EStoreEObjectImpl.BasicEStoreEList<Object>(this, eStructuralFeature)
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean contains(Object object)
+ {
+ if (isEObject())
+ {
+ int size = size();
+
+ boolean result = delegateContains(object);
+ if (hasProxies() && !result)
+ {
+ for (int i = 0; i < size; ++i)
+ {
+ EObject eObject = resolveProxy((EObject)delegateGet(i));
+ if (eObject == object)
+ {
+ return true;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ return delegateContains(object);
+ }
+ };
+
+ // return super.createList(eStructuralFeature);
}
private boolean isMap(EStructuralFeature eStructuralFeature)
@@ -1756,6 +1787,32 @@ public class CDOObjectImpl extends MinimalEStoreEObjectImpl implements InternalC
return oldObject;
}
+
+ @Override
+ public boolean contains(Object object)
+ {
+ if (isEObject())
+ {
+ int size = size();
+
+ boolean result = delegateContains(object);
+ if (hasProxies() && !result)
+ {
+ for (int i = 0; i < size; ++i)
+ {
+ EObject eObject = resolveProxy((EObject)delegateGet(i));
+ if (eObject == object)
+ {
+ return true;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ return delegateContains(object);
+ }
}
/**

Back to the top