summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2011-07-22 11:02:56 (EDT)
committerStefan Winkler2011-07-22 11:02:56 (EDT)
commit0623b8b457963b5adb8baa3a9b7d64d24fe993b3 (patch)
tree7c213d782a6b2541094c3acf44a224efade340cd
parent2a06d51331343837109c30c5161bf81cf866f811 (diff)
downloadcdo-0623b8b457963b5adb8baa3a9b7d64d24fe993b3.zip
cdo-0623b8b457963b5adb8baa3a9b7d64d24fe993b3.tar.gz
cdo-0623b8b457963b5adb8baa3a9b7d64d24fe993b3.tar.bz2
[351921] [DB] NPE in GMF notation caused by CoreTypeMappings$TMCustom.getDefaultValue
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351921
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/CoreTypeMappings.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351921_Test.java140
3 files changed, 146 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/CoreTypeMappings.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/CoreTypeMappings.java
index 6c973d3..f5baf6a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/CoreTypeMappings.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/CoreTypeMappings.java
@@ -853,6 +853,11 @@ public class CoreTypeMappings
protected Object getDefaultValue()
{
Object defaultValue = getFeature().getDefaultValue();
+ if (defaultValue == null)
+ {
+ return null;
+ }
+
EFactory factory = getFeature().getEType().getEPackage().getEFactoryInstance();
return factory.convertToString((EDataType)getFeature().getEType(), defaultValue);
}
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 14f8b6b..788c201 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
@@ -235,6 +235,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_351096_Test.class);
testClasses.add(Bugzilla_338921_Test.class);
testClasses.add(Bugzilla_351393_Test.class);
+ testClasses.add(Bugzilla_351921_Test.class);
testClasses.add(Bugzilla_352303_Test.class);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351921_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351921_Test.java
new file mode 100644
index 0000000..c80e33f
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351921_Test.java
@@ -0,0 +1,140 @@
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.common.model.EMFUtil;
+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.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+/**
+ * Copyright (c) 2004 - 2011 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:
+ * Stefan Winkler - initial API and implementation
+ */
+
+/**
+ * @author Stefan Winkler
+ */
+public class Bugzilla_351921_Test extends AbstractCDOTest
+{
+ private EPackage pkg;
+
+ private EClass cls;
+
+ private EAttribute att;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ pkg = EMFUtil.createEPackage("customTest", "ct", "http://cdo.emf.eclipse.org/customTest.ecore");
+ EDataType custom = EcoreFactory.eINSTANCE.createEDataType();
+ custom.setInstanceClass(CustomType.class);
+ custom.setName("CustomType");
+
+ pkg.getEClassifiers().add(custom);
+
+ cls = EMFUtil.createEClass(pkg, "Foobar", false, false);
+ att = EMFUtil.createEAttribute(cls, "att", custom);
+ att.setDefaultValue(null);
+
+ CDOUtil.prepareDynamicEPackage(pkg);
+ }
+
+ protected EAttribute getAtt()
+ {
+ return att;
+ }
+
+ public void testDefaultValueNull() throws CommitException
+ {
+ EObject obj = EcoreUtil.create(cls);
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOTransaction tx = session.openTransaction();
+ CDOResource res = tx.createResource(getResourcePath("/test"));
+ res.getContents().add(obj);
+ tx.commit();
+ tx.close();
+ session.close();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOView v = session.openView();
+ CDOResource res = v.getResource(getResourcePath("/test"));
+ EObject persistent = res.getContents().get(0);
+
+ CustomType pCustom = (CustomType)persistent.eGet(att);
+ assertNull(pCustom);
+
+ v.close();
+ session.close();
+ }
+ }
+
+ public static class CustomType
+ {
+ private int a = 0;
+
+ private int b = 0;
+
+ public CustomType(int _a, int _b)
+ {
+ a = _a;
+ b = _b;
+ }
+
+ public CustomType(String literal)
+ {
+ String[] values = literal.split(";");
+ if (values.length != 2)
+ {
+ throw new RuntimeException("Error: only 2 values allowed");
+ }
+ else
+ {
+ a = Integer.valueOf(values[0]);
+ b = Integer.valueOf(values[1]);
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return a + ";" + b;
+ }
+
+ public int getA()
+ {
+ return a;
+ }
+
+ public int getB()
+ {
+ return b;
+ }
+ }
+}