[
https://issues.apache.org/jira/browse/ZOOKEEPER-2680?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15848789#comment-15848789
]
ASF GitHub Bot commented on ZOOKEEPER-2680:
-------------------------------------------
Github user edwardoliveira commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/160#discussion_r98967876
--- Diff: src/java/main/org/apache/zookeeper/server/DataTree.java ---
@@ -1045,18 +1046,16 @@ private void getCounts(String path, Counts counts) {
if (node == null) {
return;
}
- Set<String> children = null;
+ String[] children = null;
int len = 0;
synchronized (node) {
- children = node.getChildren();
+ Set<String> childs = node.getChildren();
+ children = childs.toArray(new String[childs.size()]);
--- End diff --
FYI (only): I *guess* some tests broke 'cause `toArray` copies the contents
of `childs` to `children` while `node.getChildren()` returns a internal
reference (subject to underneath change) to `children`. So, it would need to be
something like `children = new HashSet<>(childs);`
> Correct DataNode.getChildren() inconsistent behaviour.
> ------------------------------------------------------
>
> Key: ZOOKEEPER-2680
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2680
> Project: ZooKeeper
> Issue Type: Bug
> Components: server
> Affects Versions: 3.4.9, 3.5.1
> Reporter: Mohammad Arshad
> Assignee: Mohammad Arshad
> Fix For: 3.4.10, 3.5.3, 3.6.0
>
> Attachments: ZOOKEEPER-2680-01.patch
>
>
> DataNode.getChildren() API returns null and empty set if there are no
> children in it depending on when the API is called. DataNode.getChildren()
> API behavior should be changed and it should always return empty set if the
> node does not have any child
> *DataNode.getChildren() API Current Behavior:*
> # returns null initially
> When DataNode is created and no children are added yet,
> DataNode.getChildren() returns null
> # returns empty set after all the children are deleted:
> created a Node
> add a child
> delete the child
> DataNode.getChildren() returns empty set.
> After fix DataNode.getChildren() should return empty set in all the above
> cases.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)