From 7a1cc86d49ba6c1175789c3558cef799821bdc2a Mon Sep 17 00:00:00 2001 From: abstraktor Date: Mon, 22 Aug 2022 18:07:09 +0100 Subject: [PATCH] Don't throw NPE if accessing null references Given I have a concept `Car` which has a nullable reference `owner` And my `aCar` has no owner When I call `aCar.getOwner()`, I erroneously got a NullPointerException Because it is calling `MPSLanguageRegistry.Companion.getInstance(getINode().getReferenceTarget("owner"))` It now returns null instead of throwing the NPE --- runtime/src/main/kotlin/Language.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/main/kotlin/Language.kt b/runtime/src/main/kotlin/Language.kt index 33936f8..73b89bb 100644 --- a/runtime/src/main/kotlin/Language.kt +++ b/runtime/src/main/kotlin/Language.kt @@ -33,7 +33,7 @@ class MPSLanguageRegistry: IConceptReferenceSerializer { language.getConcepts().forEach { conceptsById[it.getUID()] = it } } fun getInstance(iNode: INode): T? { - return (iNode.concept as AbstractConcept).createInstance(iNode) + return (iNode?.concept as? AbstractConcept)?.createInstance(iNode) } fun getConceptById(id: String):AbstractConcept<*>? { return conceptsById[id] as? AbstractConcept<*>