Repository: flex-sdk
Updated Branches:
  refs/heads/develop ff32502ec -> 11d60dae2


FLEX-34775
CAUSE: Asking the HierarchicalCollectionView to open an inaccessible node (e.g. 
a node whose parent is closed) would succeed (but should not). A consequence 
was that HierarchicalCollectionView.length was incremented (say, by 1 if that 
node had no children), which is wrong: the collection length hadn't changed 
(because the newly opened node cannot be accessed due to its closed parent), 
since the collection length represents the number of nodes that can be accessed 
by navigating it via a cursor. Then navigating this HierarchicalCollectionView 
via a cursor would enter an infinite loop because 
HierarchicalCollectionViewCursor.afterLast uses the 
HierarchicalCollectionView.length property to know when it reached the last 
node. However, if the length property is higher than reality, the cursor will 
think it never reaches the last node (because 
HierarchicalCollectionViewCursor.moveNext() will simply do nothing when it's at 
the end of the collection, which is true when HierarchicalCollectionV
 iewCursor.current is null; see HierarchicalCollectionViewCursor.moveNext).

SOLUTION: We don't allow the opening of an inaccessible node anymore.

NOTES:
-this solution is verified by HierarchicalCollectionView_FLEX_34775_Tests.
-as part of this change I also removed unused variables and corrected some 
comments in HierarchicalCollectionView.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/11d60dae
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/11d60dae
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/11d60dae

Branch: refs/heads/develop
Commit: 11d60dae25200cc80d1eadc7a2f818fff5aeac15
Parents: ff32502
Author: Mihai Chira <[email protected]>
Authored: Mon Mar 23 11:41:22 2015 +0100
Committer: Mihai Chira <[email protected]>
Committed: Mon Mar 23 11:41:22 2015 +0100

----------------------------------------------------------------------
 .../collections/HierarchicalCollectionView.as   | 39 ++++++++++----------
 1 file changed, 20 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/11d60dae/frameworks/projects/advancedgrids/src/mx/collections/HierarchicalCollectionView.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/advancedgrids/src/mx/collections/HierarchicalCollectionView.as
 
b/frameworks/projects/advancedgrids/src/mx/collections/HierarchicalCollectionView.as
index d752e8e..987a684 100644
--- 
a/frameworks/projects/advancedgrids/src/mx/collections/HierarchicalCollectionView.as
+++ 
b/frameworks/projects/advancedgrids/src/mx/collections/HierarchicalCollectionView.as
@@ -103,11 +103,6 @@ public class HierarchicalCollectionView extends 
EventDispatcher
 
     /**
      *  @private
-     */
-    private var cursor:HierarchicalCollectionViewCursor;
-
-    /**
-     *  @private
      *  The total number of nodes we know about.
      */
     private var currentLength:int;
@@ -323,7 +318,9 @@ public class HierarchicalCollectionView extends 
EventDispatcher
     //----------------------------------
 
     /**
-     *  The length of the currently parsed collection.  
+     *  The length of the currently parsed collection (i.e. the number
+     *  of nodes that can be accessed by navigating the collection via
+     *  HierarchicalCollectionViewCursor)
      *  
      *  @langversion 3.0
      *  @playerversion Flash 9
@@ -375,7 +372,7 @@ public class HierarchicalCollectionView extends 
EventDispatcher
      *
      *  @return IViewCursor instance.
      *
-     *  @see mx.utils.IViewCursor
+     *  @see mx.collections.IViewCursor
      *  
      *  @langversion 3.0
      *  @playerversion Flash 9
@@ -643,7 +640,18 @@ public class HierarchicalCollectionView extends 
EventDispatcher
         // check if the node is already opened
         if (_openNodes[uid] != null)
             return;
-        
+
+        // check if the node is accessible, abort if not
+        var parent:* = getParentItem(node);
+        while(parent)
+        {
+            parent = getParentItem(parent);
+        }
+
+        //undefined means an ancestor is not open, which means the node is 
inaccessible
+        if(parent === undefined)
+            return;
+
         // add the node to the openNodes object and update the length
         _openNodes[uid] = node;
         
@@ -792,14 +800,12 @@ public class HierarchicalCollectionView extends 
EventDispatcher
      *     </li>
      * </ul>
      *
-     *  @param node The Object that defines the parent node.
+     *  @param parent The Object that defines the parent node.
      * 
      *  @param newChild The Object that defines the child node.
      * 
      *  @param index The 0-based index of where to insert the child node.
-     * 
-     *  @param source The entire collection that this node is a part of.
-     * 
+     *
      *  @return <code>true</code> if the child is added successfully.
      *  
      *  @langversion 3.0
@@ -1295,9 +1301,9 @@ public class HierarchicalCollectionView extends 
EventDispatcher
     
     /**
      * @private
-     * Force a recalulation of length   
+     * Force a recalculation of length
      */
-     private function updateLength(node:Object=null, parent:Object = null):void
+     private function updateLength():void
      {
         currentLength = calculateLength();
      }
@@ -1527,7 +1533,6 @@ public class HierarchicalCollectionView extends 
EventDispatcher
                 }
 
                 // prune the replacements from this list
-                var j:int = 0;
                 for (i = 0; i < n; i++)
                 {
                     node = ce.items[i].oldValue;
@@ -1648,7 +1653,6 @@ public class HierarchicalCollectionView extends 
EventDispatcher
                 }
 
                 // prune the replacements from this list
-                var j:int = 0;
                 for (i = 0; i < n; i++)
                 {
                     changingNode = ce.items[i].oldValue;
@@ -1712,9 +1716,6 @@ public class HierarchicalCollectionView extends 
EventDispatcher
                                         value:Object, 
                                         detail:Object):void
     {
-        var prop:String;
-        var oldValue:Object;
-        var newValue:Object;
         var children:XMLListCollection;
         var location:int;
         var event:CollectionEvent;

Reply via email to