From 99489fdb3629b984d5f7943da6367111439333c9 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 17 Oct 2019 14:01:46 +0300 Subject: [PATCH] Fixed NPE from Change Information when given unexpected input gitlab #401 Change-Id: I31b56160e95d3169699db9fb141d10fa4046d46d --- .../org/simantics/modeling/ui/view/Bean.java | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/view/Bean.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/view/Bean.java index 0ce59433e..26e65d15b 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/view/Bean.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/view/Bean.java @@ -17,9 +17,13 @@ import org.simantics.modeling.ModelingResources; import org.simantics.modeling.adapters.ChangeInformation; import org.simantics.modeling.subscription.SubscriptionItemLabel; import org.simantics.utils.format.ValueFormat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class Bean { + private static final Logger LOGGER = LoggerFactory.getLogger(Bean.class); + public String createdBy = ""; public String modifiedBy = ""; public long modifiedAt = 0; @@ -78,24 +82,29 @@ public class Bean { Resource parent = graph.getPossibleObject(r, L0.PartOf); if(parent != null) { String uri = graph.getPossibleURI(parent); - if(uri.endsWith("/__CONTAINER__/__DIAGRAM__")) uri = uri.substring(0, uri.length()-"/__CONTAINER__/__DIAGRAM__".length()); - if(uri.endsWith("/__CONTAINER__")) uri = uri.substring(0, uri.length()-"/__CONTAINER__".length()); - if(uri.equals(baseURI)) uri = ""; - if(uri.startsWith(baseURI)) uri = uri.substring(baseURI.length()); - if(uri.startsWith("/Configuration/")) uri = uri.substring("/Configuration/".length()); - - uri = uri.replace("http://Projects/Development%20Project/", ""); - uri = URIStringUtils.unescape(uri); - - if(graph.isInstanceOf(parent, MOD.Subscription)) { + if (uri != null) { + if(uri.endsWith("/__CONTAINER__/__DIAGRAM__")) uri = uri.substring(0, uri.length()-"/__CONTAINER__/__DIAGRAM__".length()); + if(uri.endsWith("/__CONTAINER__")) uri = uri.substring(0, uri.length()-"/__CONTAINER__".length()); + if(uri.equals(baseURI)) uri = ""; + if(uri.startsWith(baseURI)) uri = uri.substring(baseURI.length()); + if(uri.startsWith("/Configuration/")) uri = uri.substring("/Configuration/".length()); + + uri = uri.replace("http://Projects/Development%20Project/", ""); + uri = URIStringUtils.unescape(uri); + + if(graph.isInstanceOf(parent, MOD.Subscription)) { - String name = graph.getPossibleRelatedValue(parent, L0.HasName, Bindings.STRING); - String label = graph.getPossibleRelatedValue(parent, L0.HasLabel, Bindings.STRING); - uri = uri.replace(name, label); - + String name = graph.getPossibleRelatedValue(parent, L0.HasName, Bindings.STRING); + String label = graph.getPossibleRelatedValue(parent, L0.HasLabel, Bindings.STRING); + uri = uri.replace(name, label); + + } + + setPath(uri); + } else { + LOGGER.warn("Could not resolve path (URI) for parent resource {} of child {}", parent, r); + setPath(""); } - - setPath(uri); } else { setPath(""); } -- 2.47.1