]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Fix possible NPE when handling added and removed properties 00/2000/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 13 Aug 2018 07:27:53 +0000 (10:27 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 13 Aug 2018 07:27:53 +0000 (10:27 +0300)
gitlab #2

Change-Id: Iea39d4965096726162cc085a872c411e7433fa4b

org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java
org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java

index cbdfc8f48f5cefe15c5b2ffe570b0201b269c509..d76c47bdf655998c902de59f6f2b7f08c58f7bd8 100644 (file)
@@ -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;
                                        }
index 25d43592f7491662b349674d0bc80d5d61ce69a8..69256b0381ed7549ed4f4484734b6ddbbf306fc6 100644 (file)
@@ -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<Statement, Statement>(first, second);
                this.changes = changes;
        }
        
        public PropertyChange(GraphChanges changes, Pair<Statement, Statement> 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;
+       }
+       
 }