From: Marko Luukkainen Date: Mon, 13 Aug 2018 07:27:53 +0000 (+0300) Subject: Fix possible NPE when handling added and removed properties X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ab4fc05981803ce2c430f93f34b8b6a8f85a53ce;p=simantics%2Finterop.git Fix possible NPE when handling added and removed properties gitlab #2 Change-Id: Iea39d4965096726162cc085a872c411e7433fa4b --- diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java index cbdfc8f..d76c47b 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java @@ -240,7 +240,11 @@ public abstract class ModelUpdate { for (PropertyChange rc : r) { if (comparable.containsRight(rc)) continue; - if (lc.getFirst().equals(rc.getFirst())) { + if (lc.getFirst() != null && lc.getFirst().equals(rc.getFirst())) { + comparable.map(lc, rc); + break; + } + if (lc.getSecond() != null && lc.getSecond().equals(rc.getSecond())) { comparable.map(lc, rc); break; } @@ -471,7 +475,7 @@ public abstract class ModelUpdate { if (pair.getFirst() != null) { boolean found = false; for (PropertyChange pair2 : updateList2.getChanges()) { - if (pair.getFirst().equals(pair2.getSecond())) { + if (pair.getFirst() != null && pair.getFirst().equals(pair2.getSecond())) { found = true; break; } diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java index 25d4359..69256b0 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java @@ -16,11 +16,15 @@ public class PropertyChange { public PropertyChange(GraphChanges changes, Statement first, Statement second) { + if (first == null && second == null) + throw new IllegalArgumentException("At least one of the stamenents must be non null."); this.pair = new Pair(first, second); this.changes = changes; } public PropertyChange(GraphChanges changes, Pair change) { + if (change == null || (change.first == null && change.second == null)) + throw new IllegalArgumentException("At least one of the stamenents must be non null."); this.pair = change; this.changes = changes; } @@ -96,4 +100,14 @@ public class PropertyChange { this.visible = visible; } + @Override + public String toString() { + String s = "PropertyChange"; + if (pair.first != null) + s += " (" + (pair.first.getSubject()) + " , " + pair.first.getPredicate() + " , " + pair.first.getObject() + ")"; + if (pair.second != null) + s += " (" + (pair.second.getSubject()) + " , " + pair.second.getPredicate() + " , " + pair.second.getObject() + ")"; + return s; + } + }