Revision: 3808
Author: [email protected]
Date: Thu Jul 29 12:18:09 2010
Log: Added a test to PersistedSPObjectTest to ensure that the parent property of an SPObject is only and must be set to null after firing a child removed event.

Previously, there were cases of SPObjects that set the parent property to null before firing a child removed event, which caused SPPersisterListener's propertyChanged method to throw an exception because its root object does not have a runnable dispatcher reference.

Furthermore, SPObjects that do not set the parent property to null after firing a child removed event could cause misleading and unexpected behaviour. For example, anything that still has a reference to the removed child could call getParent() and be returned a non-null value.

With this new test, all of the offending SPObjects that violate this test have been fixed.
http://code.google.com/p/power-architect/source/detail?r=3808

Modified:
 /trunk/src/main/java/ca/sqlpower/architect/profile/ColumnProfileResult.java
 /trunk/src/main/java/ca/sqlpower/architect/profile/TableProfileResult.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/ColumnProfileResult.java Fri Jul 16 13:23:39 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/ColumnProfileResult.java Thu Jul 29 12:18:09 2010
@@ -275,7 +275,7 @@
     @Override
     @Mutator
     public void setParent(SPObject parent) {
-        if (!(parent instanceof TableProfileResult)) {
+        if (parent != null && !(parent instanceof TableProfileResult)) {
throw new IllegalArgumentException("Parent of " + this + " must be of type " +
                     TableProfileResult.class);
         }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/TableProfileResult.java Fri Jul 16 07:18:35 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/TableProfileResult.java Thu Jul 29 12:18:09 2010
@@ -283,6 +283,7 @@
             int index = columnProfileResults.indexOf(child);
             if (columnProfileResults.remove(child)) {
                 fireChildRemoved(ColumnProfileResult.class, child, index);
+                child.setParent(null);
             }
         }
         return false;

Reply via email to