]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed NPE from Change Information when given unexpected input 57/3357/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 17 Oct 2019 11:01:46 +0000 (14:01 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 17 Oct 2019 11:01:46 +0000 (14:01 +0300)
gitlab #401

Change-Id: I31b56160e95d3169699db9fb141d10fa4046d46d

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/view/Bean.java

index 0ce59433e0bb23cfb408ce23915f92db844b38fa..26e65d15b6b516ce7bd10145859a58f4be5630cc 100644 (file)
@@ -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 = "<selected resource>";
-                       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 = "<selected resource>";
+                               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("");
                }