From 9a28ac3a85fc79dbea041ccf18ddb35d1979b125 Mon Sep 17 00:00:00 2001 From: Michael Huster Date: Tue, 14 Nov 2023 11:56:50 +0100 Subject: [PATCH] fix(mps-model-adapters): handle unresolvable model imports If an imported model could not be resolved, it caused a NullPointerException. This change handles this case gracefully. --- .../kotlin/org/modelix/model/mpsadapters/MPSModelAsNode.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mps-model-adapters/src/main/kotlin/org/modelix/model/mpsadapters/MPSModelAsNode.kt b/mps-model-adapters/src/main/kotlin/org/modelix/model/mpsadapters/MPSModelAsNode.kt index 7e26b74c7e..11b678f6f5 100644 --- a/mps-model-adapters/src/main/kotlin/org/modelix/model/mpsadapters/MPSModelAsNode.kt +++ b/mps-model-adapters/src/main/kotlin/org/modelix/model/mpsadapters/MPSModelAsNode.kt @@ -76,8 +76,9 @@ data class MPSModelAsNode(val model: SModel) : IDefaultNodeAdapter { } else if (link.conformsTo(BuiltinLanguages.MPSRepositoryConcepts.Model.rootNodes)) { model.rootNodes.map { MPSNode(it) } } else if (link.conformsTo(BuiltinLanguages.MPSRepositoryConcepts.Model.modelImports)) { - ModelImports(model).importedModels.mapNotNull { - MPSModelImportAsNode(it.resolve(model.repository), model) + ModelImports(model).importedModels.mapNotNull { modelRef -> + val target = modelRef.resolve(model.repository) + target?.let { MPSModelImportAsNode(it, model) } } } else if (link.conformsTo(BuiltinLanguages.MPSRepositoryConcepts.Model.usedLanguages)) { getImportedLanguagesAndDevKits()