Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDennis Wagelaar2018-09-18 04:30:26 -0400
committerDennis Wagelaar2018-09-18 04:30:26 -0400
commit4f71541bbf48342f4dfbeefec674a7a7b3e0520b (patch)
tree9070dc333e8b3d2704a483fdc521286a2514b69e
parentd52f9cad02db1f61c331df537e988d374c972a1e (diff)
downloadorg.eclipse.atl-4f71541bbf48342f4dfbeefec674a7a7b3e0520b.tar.gz
org.eclipse.atl-4f71541bbf48342f4dfbeefec674a7a7b3e0520b.tar.xz
org.eclipse.atl-4f71541bbf48342f4dfbeefec674a7a7b3e0520b.zip
535793: NullPointerException in EMFTVMUtil#checkValueTypeIsEObject()
Change-Id: I9c1d18959bb03a48a72c2e8029522065c1cb76c1 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=535793 Signed-off-by: Dennis Wagelaar <dwagelaar@gmail.com>
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java11
-rw-r--r--tests/org.eclipse.m2m.atl.emftvm.tests/src/org/eclipse/m2m/atl/emftvm/util/tests/EMFTVMUtilTest.java68
2 files changed, 72 insertions, 7 deletions
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
index 9bcd51a0..cfdbb110 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
+++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
@@ -878,9 +878,12 @@ public final class EMFTVMUtil {
*/
private static void checkValueTypeIsEObject(final ExecEnv env, final EReference ref, final Object v) {
if (!(v instanceof EObject)) {
- throw new IllegalArgumentException(String.format(
- "Cannot add/remove values of type %s to/from multi-valued field %s::%s",
- getTypeName(env, v.getClass()), ref.getEContainingClass().getName(), ref.getName()));
+ final String message = v == null
+ ? String.format("Cannot add/remove OclUndefined to/from multi-valued field %s::%s",
+ ref.getEContainingClass().getName(), ref.getName())
+ : String.format("Cannot add/remove values of type %s to/from multi-valued field %s::%s",
+ getTypeName(env, v.getClass()), ref.getEContainingClass().getName(), ref.getName());
+ throw new IllegalArgumentException(message);
}
}
@@ -999,7 +1002,7 @@ public final class EMFTVMUtil {
private static void addRefValue(final ExecEnv env, final EReference ref, final EObject eo, final Collection<Object> values,
final EObject v, final int index, final boolean allowInterModelReferences) {
assert eo.eResource() != null;
- assert v.eResource() != null;
+ assert v == null || v.eResource() != null;
if (checkValue(env, eo, ref, v, allowInterModelReferences)) {
if (index > -1) {
((List<Object>) values).add(index, v);
diff --git a/tests/org.eclipse.m2m.atl.emftvm.tests/src/org/eclipse/m2m/atl/emftvm/util/tests/EMFTVMUtilTest.java b/tests/org.eclipse.m2m.atl.emftvm.tests/src/org/eclipse/m2m/atl/emftvm/util/tests/EMFTVMUtilTest.java
index 99bc7732..1aab17b9 100644
--- a/tests/org.eclipse.m2m.atl.emftvm.tests/src/org/eclipse/m2m/atl/emftvm/util/tests/EMFTVMUtilTest.java
+++ b/tests/org.eclipse.m2m.atl.emftvm.tests/src/org/eclipse/m2m/atl/emftvm/util/tests/EMFTVMUtilTest.java
@@ -22,6 +22,8 @@ import java.util.Map;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.m2m.atl.emftvm.CodeBlock;
import org.eclipse.m2m.atl.emftvm.EmftvmFactory;
import org.eclipse.m2m.atl.emftvm.EmftvmPackage;
@@ -137,7 +139,7 @@ public class EMFTVMUtilTest extends TestCase {
try {
EMFTVMUtil.set(env, eo, sf, value);
- fail("Expected VMException");
+ fail("Expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
assertEquals("Cannot add/remove values of type Sequence to/from multi-valued field CodeBlock::code",
e.getMessage());
@@ -158,7 +160,7 @@ public class EMFTVMUtilTest extends TestCase {
try {
EMFTVMUtil.add(env, eo, sf, value, 0);
- fail("Expected VMException");
+ fail("Expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
assertEquals("Cannot add/remove values of type Sequence to/from multi-valued field CodeBlock::code",
e.getMessage());
@@ -178,7 +180,7 @@ public class EMFTVMUtilTest extends TestCase {
try {
EMFTVMUtil.remove(env, eo, sf, value);
- fail("Expected VMException");
+ fail("Expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
assertEquals("Cannot add/remove values of type Sequence to/from multi-valued field CodeBlock::code",
e.getMessage());
@@ -186,6 +188,66 @@ public class EMFTVMUtilTest extends TestCase {
}
/**
+ * Test method for
+ * {@link EMFTVMUtil#set(ExecEnv, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EStructuralFeature, Object)}.
+ */
+ public void testSet_null() {
+ final Resource res = new ResourceImpl();
+ final ExecEnv env = EmftvmFactory.eINSTANCE.createExecEnv();
+ final CodeBlock eo = EmftvmFactory.eINSTANCE.createCodeBlock();
+ res.getContents().add(eo);
+ final EReference sf = EmftvmPackage.eINSTANCE.getCodeBlock_Code();
+ final LazyList<Instruction> value = new LazyList<Instruction>().append(null);
+
+ try {
+ EMFTVMUtil.set(env, eo, sf, value);
+ fail("Expected IllegalArgumentException");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Cannot add/remove OclUndefined to/from multi-valued field CodeBlock::code", e.getMessage());
+ }
+ }
+
+ /**
+ * Test method for {@link EMFTVMUtil#add(ExecEnv, org.eclipse.emf.ecore.EObject,
+ * org.eclipse.emf.ecore.EStructuralFeature, Object, int).
+ */
+ public void testAdd_null() {
+ final Resource res = new ResourceImpl();
+ final ExecEnv env = EmftvmFactory.eINSTANCE.createExecEnv();
+ final CodeBlock eo = EmftvmFactory.eINSTANCE.createCodeBlock();
+ res.getContents().add(eo);
+ final EReference sf = EmftvmPackage.eINSTANCE.getCodeBlock_Code();
+ final LazyList<Instruction> value = new LazyList<Instruction>().append(null);
+
+ try {
+ EMFTVMUtil.add(env, eo, sf, value, 0);
+ fail("Expected IllegalArgumentException");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Cannot add/remove OclUndefined to/from multi-valued field CodeBlock::code", e.getMessage());
+ }
+ }
+
+ /**
+ * Test method for
+ * {@link EMFTVMUtil#remove(ExecEnv, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EStructuralFeature, Object)}.
+ */
+ public void testRemove_null() {
+ final Resource res = new ResourceImpl();
+ final ExecEnv env = EmftvmFactory.eINSTANCE.createExecEnv();
+ final CodeBlock eo = EmftvmFactory.eINSTANCE.createCodeBlock();
+ res.getContents().add(eo);
+ final EReference sf = EmftvmPackage.eINSTANCE.getCodeBlock_Code();
+ final LazyList<Instruction> value = new LazyList<Instruction>().append(null);
+
+ try {
+ EMFTVMUtil.remove(env, eo, sf, value);
+ fail("Expected IllegalArgumentException");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Cannot add/remove OclUndefined to/from multi-valued field CodeBlock::code", e.getMessage());
+ }
+ }
+
+ /**
* Test method for {@link EMFTVMUtil#findRootMethod(Method)}.
*/
public void testFindRootMethod() {

Back to the top