summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2010-05-18 10:13:58 (EDT)
committerStefan Winkler2010-05-18 10:13:58 (EDT)
commit58be8494d24ff32eb8731fa2fb97219698bab3a6 (patch)
tree008b271828f75201b84dd0a37c1fc57c3f97c917
parent32005f540b0228e5693449f2afdb7716580f0c16 (diff)
downloadcdo-58be8494d24ff32eb8731fa2fb97219698bab3a6.zip
cdo-58be8494d24ff32eb8731fa2fb97219698bab3a6.tar.gz
cdo-58be8494d24ff32eb8731fa2fb97219698bab3a6.tar.bz2
[306998] [DB] NullPointerException when invalid default value literal of EENum type
https://bugs.eclipse.org/bugs/show_bug.cgi?id=306998
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/messages/messages.properties1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_306998_Test.java107
4 files changed, 119 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
index 697aa8c..824523d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
@@ -30,6 +30,7 @@ import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
import org.eclipse.emf.cdo.server.internal.db.DBAnnotation;
import org.eclipse.emf.cdo.server.internal.db.MetaDataManager;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
+import org.eclipse.emf.cdo.server.internal.db.messages.Messages;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBType;
@@ -49,6 +50,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
+import java.text.MessageFormat;
import java.util.Calendar;
import java.util.Date;
@@ -296,6 +298,13 @@ public abstract class TypeMapping implements ITypeMapping
if (defaultValueLiteral != null)
{
EEnumLiteral literal = eenum.getEEnumLiteralByLiteral(defaultValueLiteral);
+ if (literal == null)
+ {
+ OM.LOG.warn(MessageFormat.format(
+ Messages.getString("DBStore.13"), getFeature().getDefaultValueLiteral(), getFeature())); //$NON-NLS-1$
+ literal = (EEnumLiteral)eenum.getDefaultValue();
+ }
+
return literal.getValue();
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/messages/messages.properties b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/messages/messages.properties
index 76fd83d..5b9baba 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/messages/messages.properties
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/messages/messages.properties
@@ -17,3 +17,4 @@ DBStore.8=First start: {0,date} {0,time}
DBStore.9=Detected crash
DBStore.11=BranchingSupport of MappingStrategy and Store do not match. Please check configuration.
DBStore.12=Repairing after crash failed.
+DBStore.13=Invalid EENum default literal {0} for model element {1}. Falling back to EENum default value.
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
index b440940..ebbf6d4 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
@@ -69,6 +69,7 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_302233_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303466_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303807_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_306710_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_306998_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_308895_Test;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
@@ -199,6 +200,7 @@ public abstract class AllTestsAllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_303466_Test.class);
testClasses.add(Bugzilla_303807_Test.class);
testClasses.add(Bugzilla_306710_Test.class);
+ testClasses.add(Bugzilla_306998_Test.class);
testClasses.add(Bugzilla_308895_Test.class);
// TODO testClasses.add(NonCDOResourceTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_306998_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_306998_Test.java
new file mode 100644
index 0000000..3b1d0c7
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_306998_Test.java
@@ -0,0 +1,107 @@
+/**
+ * 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:
+ * Eike Stepper - initial API and implementation
+ */
+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.tests.legacy.model1.Model1Package;
+import org.eclipse.emf.cdo.tests.model1.VAT;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public class Bugzilla_306998_Test extends AbstractCDOTest
+{
+ public void testValidEENumLiteral()
+ {
+ EPackage pkg = EMFUtil.createEPackage("pkg", "pkg", "http://cdo.eclipse.org/Bugzilla_306998_Test_1.ecore");
+ EClass cls = EMFUtil.createEClass(pkg, "cls", false, false);
+ EAttribute att = EMFUtil.createEAttribute(cls, "att", Model1Package.eINSTANCE.getVAT());
+ att.setDefaultValueLiteral("vat7");
+
+ CDOUtil.prepareDynamicEPackage(pkg);
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOTransaction tx = session.openTransaction();
+ CDOResource res = tx.createResource("/test");
+
+ EObject obj = EcoreUtil.create(cls);
+
+ res.getContents().add(obj);
+ tx.commit();
+ tx.close();
+ session.close();
+ }
+ clearCache(getRepository().getRevisionManager());
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOView view = session.openView();
+ CDOResource res = view.getResource("/test");
+
+ EObject obj = res.getContents().get(0);
+ assertEquals(7, ((VAT)obj.eGet(att)).getValue());
+
+ view.close();
+ session.close();
+ }
+ }
+
+ public void testInalidEENumLiteral()
+ {
+ EPackage pkg = EMFUtil.createEPackage("pkg", "pkg", "http://cdo.eclipse.org/Bugzilla_306998_Test_1.ecore");
+ EClass cls = EMFUtil.createEClass(pkg, "cls", false, false);
+ EAttribute att = EMFUtil.createEAttribute(cls, "att", Model1Package.eINSTANCE.getVAT());
+ att.setDefaultValueLiteral("vat8");
+
+ CDOUtil.prepareDynamicEPackage(pkg);
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOTransaction tx = session.openTransaction();
+ CDOResource res = tx.createResource("/test");
+
+ EObject obj = EcoreUtil.create(cls);
+
+ res.getContents().add(obj);
+ tx.commit();
+ tx.close();
+ session.close();
+ }
+ clearCache(getRepository().getRevisionManager());
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOView view = session.openView();
+ CDOResource res = view.getResource("/test");
+
+ EObject obj = res.getContents().get(0);
+ assertEquals(0, ((VAT)obj.eGet(att)).getValue());
+
+ view.close();
+ session.close();
+ }
+ }
+}