From 59490a4c786ebda6868e0b7db91563e73f7c8384 Mon Sep 17 00:00:00 2001 From: Didier Vojtisek Date: Fri, 24 Jan 2020 09:03:31 +0100 Subject: [PATCH] makes IntrospectiveMutableFieldExtractor more robust (#150) in some metamodels, the attribute "name" or "id" may be present but set to null. These changes avoid the NullPointerException in this case. Signed-off-by: Didier Vojtisek --- .../IntrospectiveMutableFieldExtractor.xtend | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.debugger/src/org/eclipse/gemoc/executionframework/debugger/IntrospectiveMutableFieldExtractor.xtend b/framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.debugger/src/org/eclipse/gemoc/executionframework/debugger/IntrospectiveMutableFieldExtractor.xtend index 6c731f277..361495e8d 100644 --- a/framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.debugger/src/org/eclipse/gemoc/executionframework/debugger/IntrospectiveMutableFieldExtractor.xtend +++ b/framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.debugger/src/org/eclipse/gemoc/executionframework/debugger/IntrospectiveMutableFieldExtractor.xtend @@ -50,7 +50,7 @@ class IntrospectiveMutableFieldExtractor implements IMutableFieldExtractor { val name = cls.declaredFields.filter[f|f.name.equals("name")] if (name.empty) { // Try again on superclass if it's not EObjectImpl. - if (cls.superclass != EObjectImpl) { + if (cls.superclass != EObjectImpl && cls.superclass !== null) { return findName(cls.superclass, eObject) } // No field called "name" accessible on the given EObject, return null. @@ -59,7 +59,13 @@ class IntrospectiveMutableFieldExtractor implements IMutableFieldExtractor { // A field called "name" has been found, return its value. val f = name.get(0) f.accessible = true - return f.get(eObject).toString + val o = f.get(eObject) + if(o !== null) { + return f.get(eObject).toString + } else { + // the value stored in the attribute is null + return null + } } } @@ -68,7 +74,7 @@ class IntrospectiveMutableFieldExtractor implements IMutableFieldExtractor { val id = cls.declaredFields.filter[f|f.name.equals("id")] if (id.empty) { // Try again on superclass if it's not EObjectImpl. - if (cls.superclass != EObjectImpl) { + if (cls.superclass != EObjectImpl && cls.superclass !== null) { return findId(cls.superclass, eObject) } // No field called "id" accessible on the given EObject, return null. @@ -77,7 +83,13 @@ class IntrospectiveMutableFieldExtractor implements IMutableFieldExtractor { // A field called "id" has been found, return its value. val f = id.get(0) f.accessible = true - return f.get(eObject).toString + val o = f.get(eObject) + if(o !== null) { + return f.get(eObject).toString + } else { + // the value stored in the attribute is null + return null + } } }