[
https://issues.apache.org/jira/browse/ZOOKEEPER-4325?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ling Mao resolved ZOOKEEPER-4325.
---------------------------------
Fix Version/s: (was: 3.6.2)
3.8.0
Resolution: Fixed
> IllegalArgumentException when use ZkUtil::listSubTreeBFS to list "/"
> --------------------------------------------------------------------
>
> Key: ZOOKEEPER-4325
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4325
> Project: ZooKeeper
> Issue Type: Bug
> Components: server
> Affects Versions: 3.6.2
> Reporter: Reno Shen
> Priority: Minor
> Labels: pull-request-available
> Fix For: 3.8.0
>
> Time Spent: 4.5h
> Remaining Estimate: 0h
>
> [ZkUtil::listSubTreeBFS|https://github.com/apache/zookeeper/blob/branch-3.6/zookeeper-server/src/main/java/org/apache/zookeeper/ZKUtil.java]
> Assume zk has these nodes: /a_test/a, /b_test/b.
> When use this method to list "/", according to BFS logic, the BFS queue would
> be added node like: "//a_test", then getChildren by this path, the next
> exception occurs:
> {code:java}
> java.lang.IllegalArgumentException: Invalid path string "//a_test" caused by
> empty node name specified @1
> {code}
>
> Solutions:
> {code:java}
> public static List<String> listSubTreeBFS(
> ZooKeeper zk,
> final String pathRoot) throws KeeperException, InterruptedException {
> Queue<String> queue = new ArrayDeque<>();
> List<String> tree = new ArrayList<>();
> queue.add(pathRoot);
> tree.add(pathRoot);
> while (!queue.isEmpty()) {
> String node = queue.poll();
> List<String> children = zk.getChildren(node, false);
> for (final String child : children) {
> // Fix "//some_path" bugs when list "/"
> final String childPath = (node.equals("/") ? "" : node) + "/" +
> child;
> queue.add(childPath);
> tree.add(childPath);
> }
> }
> return tree;
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)