Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-04-07 09:05:49 +0000
committerEike Stepper2013-04-07 09:05:49 +0000
commit540e46582a4dc392c85569899ab1bbab36888872 (patch)
tree7bc61e93d3a8665ac31fdb8a6186b7d3b200d804
parentf2af641004b144f4e0330e20ed9a5abeaeda15b0 (diff)
downloadcdo-540e46582a4dc392c85569899ab1bbab36888872.tar.gz
cdo-540e46582a4dc392c85569899ab1bbab36888872.tar.xz
cdo-540e46582a4dc392c85569899ab1bbab36888872.zip
[402670] NPE on Rollback after changing a boolean value
https://bugs.eclipse.org/bugs/show_bug.cgi?id=402670
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_402670_Test.java47
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java58
2 files changed, 62 insertions, 43 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_402670_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_402670_Test.java
new file mode 100644
index 0000000000..ca17e4e2b4
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_402670_Test.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2004 - 2013 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:
+ * Steve Monnier - 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.Supplier;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+/**
+ * Bug 402670.
+ *
+ * @author Steve Monnier
+ */
+public class Bugzilla_402670_Test extends AbstractCDOTest
+{
+ /**
+ * This scenario validates that rollbacking a boolean value change doesn't throw an NPE.
+ */
+ public void testRollbackOfBooleanValueChange() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/my/resource"));
+
+ Company company = getModel1Factory().createCompany();
+ resource.getContents().add(company);
+
+ Supplier supplier = getModel1Factory().createSupplier();
+ supplier.setPreferred(true);
+ company.getSuppliers().add(supplier);
+ transaction.commit();
+
+ supplier.setPreferred(false);
+ transaction.rollback();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java
index cc6cb35e28..5c1cbcdf10 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java
@@ -286,52 +286,24 @@ public class CDONotificationBuilder extends CDOFeatureDeltaVisitorImpl
Object newValue, int position)
{
Class<?> instanceClass = feature.getEType().getInstanceClass();
- if (instanceClass == Integer.TYPE)
+ if (instanceClass.isPrimitive())
{
- int old = oldValue == null ? 0 : ((Integer)oldValue).intValue();
- return new CDODeltaNotificationImpl(object, eventType, feature, old, ((Integer)newValue).intValue());
- }
-
- if (instanceClass == Boolean.TYPE)
- {
- boolean old = oldValue == null ? false : ((Boolean)oldValue).booleanValue();
- return new CDODeltaNotificationImpl(object, eventType, feature, old, ((Boolean)newValue).booleanValue());
- }
-
- if (instanceClass == Long.TYPE)
- {
- long old = oldValue == null ? 0 : ((Long)oldValue).longValue();
- return new CDODeltaNotificationImpl(object, eventType, feature, old, ((Long)newValue).longValue());
- }
-
- if (instanceClass == Float.TYPE)
- {
- float old = oldValue == null ? 0 : ((Float)oldValue).floatValue();
- return new CDODeltaNotificationImpl(object, eventType, feature, old, ((Float)newValue).floatValue());
- }
-
- if (instanceClass == Double.TYPE)
- {
- double old = oldValue == null ? 0 : ((Double)oldValue).doubleValue();
- return new CDODeltaNotificationImpl(object, eventType, feature, old, ((Double)newValue).doubleValue());
- }
-
- if (instanceClass == Short.TYPE)
- {
- short old = oldValue == null ? 0 : ((Short)oldValue).shortValue();
- return new CDODeltaNotificationImpl(object, eventType, feature, old, ((Short)newValue).shortValue());
- }
+ Object defaultValue = null;
+ if (oldValue == null)
+ {
+ defaultValue = feature.getDefaultValue();
+ oldValue = defaultValue;
+ }
- if (instanceClass == Byte.TYPE)
- {
- byte old = oldValue == null ? 0 : ((Byte)oldValue).byteValue();
- return new CDODeltaNotificationImpl(object, eventType, feature, old, ((Byte)newValue).byteValue());
- }
+ if (newValue == null)
+ {
+ if (defaultValue == null)
+ {
+ defaultValue = feature.getDefaultValue();
+ }
- if (instanceClass == Character.TYPE)
- {
- char old = oldValue == null ? 0 : ((Character)oldValue).charValue();
- return new CDODeltaNotificationImpl(object, eventType, feature, old, ((Character)newValue).charValue());
+ newValue = defaultValue;
+ }
}
return new CDODeltaNotificationImpl(object, eventType, feature, oldValue, newValue, position);

Back to the top