Node.detachAllChildren() possible bug?

Old method don't make null children ArrayList.

But the first access it is null.



Is better modify to return a null ArrayList when invoking getChildren() methods or is better nullify the children ArrayList in public method detachAllChildren like this?



    public void detachAllChildren() {

        if(children != null) {

            for ( int i = children.size() - 1; i >= 0; i-- ) {

                detachChildAt( i );

            }

            logger.info("All children removed.");

            children = null;

        }

    }

Children is null by default to avoid unnecessary object creation… however, if a Node has had children, it is more likely to have children in the future, so I don't see any reason to force it back to null.

That's why you'd use the provided getQuantity()  :slight_smile:


if (node.getChildren() != null)



fail if is called after node.deteachAllChildren(), because the ArrayList is not null.

If you use condition

if (node.getChildren().isEmpty())


"valid context after populating node", fail at first time by nullReferenceException.