From bd6d9d66a3dff294984e10ba121c9cae96edc8a6 Mon Sep 17 00:00:00 2001 From: Doris Lam Date: Wed, 16 Aug 2023 11:20:14 -0700 Subject: [PATCH] fix potential npe --- .../mdk/mms/actions/UpdateClientElementAction.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openmbee/mdk/mms/actions/UpdateClientElementAction.java b/src/main/java/org/openmbee/mdk/mms/actions/UpdateClientElementAction.java index d6c1023d0..1c07d1a18 100644 --- a/src/main/java/org/openmbee/mdk/mms/actions/UpdateClientElementAction.java +++ b/src/main/java/org/openmbee/mdk/mms/actions/UpdateClientElementAction.java @@ -265,6 +265,10 @@ public void onFailure() { if (sysmlIdJsonNode == null || !sysmlIdJsonNode.isTextual()) { continue; } + JsonNode typeNode = entryObjectNode.get(MDKConstants.TYPE_KEY); + if (typeNode == null) { // this may happen with ve added artifacts in a beta version that's not attached to a model element + continue; + } String entryId = sysmlIdJsonNode.asText(); // TODO Abstract this stuff to a converter @donbot String name = null; @@ -277,8 +281,9 @@ public void onFailure() { name = "<>"; } } + String type = typeNode != null ? typeNode.asText("Element") : "Element"; ValidationRuleViolation validationRuleViolation = new ValidationRuleViolation(entryElement != null && !Project.isElementDisposed(entryElement) ? entryElement : project.getPrimaryModel(), "[" - + (entryElement != null && !Project.isElementDisposed(entryElement) ? "UPDATE" : "CREATE") + " FAILED]" + (entryElement == null || Project.isElementDisposed(entryElement) ? " " + entryObjectNode.get(MDKConstants.TYPE_KEY).asText("Element") + " " + name + " : " + entryId : "") + + (entryElement != null && !Project.isElementDisposed(entryElement) ? "UPDATE" : "CREATE") + " FAILED]" + (entryElement == null || Project.isElementDisposed(entryElement) ? " " + type + " " + name + " : " + entryId : "") + ((entryElement == null || Project.isElementDisposed(entryElement)) && entryException != null ? " -" : "") + (entryException != null ? " " + (entryException instanceof ReadOnlyElementException ? "Element is not editable." : entryException.getMessage()) : "")); addUpdateElementActions(validationRuleViolation, entryElement, entryId, entryObjectNode); (entryException instanceof ReadOnlyElementException ? editableValidationRule : failedChangeValidationRule).addViolation(validationRuleViolation);