Skip to content

Commit

Permalink
makes IntrospectiveMutableFieldExtractor more robust (#150)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dvojtise authored Jan 24, 2020
1 parent e4539f9 commit 59490a4
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
}
}

Expand All @@ -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.
Expand All @@ -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
}
}
}

Expand Down

0 comments on commit 59490a4

Please sign in to comment.