FLEX-18746 CAUSE: HierarchicalCollectionView.updateLength() was ignoring nodes without children, as it should. However, the function it called for the nodes with children, getChildren() unfortunately had a necessary side-effect (which is a poor design choice, to be sure), which was to add an event listener to the children collection. So the empty collections of nodes were not listened to, which meant that once the node was open any children that were added to that node were not counted towards the length of the collection. And one way this inconsistency surfaced was through the expandItem() fatal.

SOLUTION: The best - and most time-consuming - solution to this is to find a way to extract the side-effect of getChildren() into a separate function and call it when needed. However, for the moment I have opted to simply allow getChildren() to be called even for empty nodes, which in turn adds the event listeners.

NOTES: all unit tests now pass.
diff --git a/frameworks/projects/mx/src/mx/controls/Tree.as b/frameworks/projects/mx/src/mx/controls/Tree.as
index 5f9215a..5bf874f 100644
--- a/frameworks/projects/mx/src/mx/controls/Tree.as
+++ b/frameworks/projects/mx/src/mx/controls/Tree.as
@@ -1783,7 +1783,7 @@
             // is the item on screen?
             if (visibleData[uid])
             {
-                //find the rowindex of the row after the open thats opening/closing
+                //find the row index of the first row after the one that's opening/closing
                 var n:int = listItems.length;
                 for (rowIndex = 0; rowIndex < n; rowIndex++)
                 {
diff --git a/frameworks/projects/mx/src/mx/controls/treeClasses/HierarchicalCollectionView.as b/frameworks/projects/mx/src/mx/controls/treeClasses/HierarchicalCollectionView.as
index 5f357b0..59fe7e8 100644
--- a/frameworks/projects/mx/src/mx/controls/treeClasses/HierarchicalCollectionView.as
+++ b/frameworks/projects/mx/src/mx/controls/treeClasses/HierarchicalCollectionView.as
@@ -267,7 +267,7 @@
 			var modelCursor:IViewCursor = treeData.createCursor();
 			if (modelCursor.beforeFirst)
 			{
-				// indicates that an IPE occured on the first item
+				// indicates that an IPE occurred on the first item
 				return treeData.length;
 			}
 			while (!modelCursor.afterLast)
@@ -315,8 +315,7 @@
 			parentMap[uid] = parent;
 			if (node != null &&
 				openNodes[uid] &&
-				dataDescriptor.isBranch(node, treeData) &&
-				dataDescriptor.hasChildren(node, treeData))
+				dataDescriptor.isBranch(node, treeData))
 			{
 				childNodes = getChildren(node);
 				if (childNodes != null)
@@ -432,7 +431,7 @@
     
     /**
 	 * @private
-	 * delegate getchildren in order to add event listeners for nested collections
+	 * delegate getChildren in order to add event listeners for nested collections
 	 */
 	private function getChildren(node:Object):ICollectionView
 	{