Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
3.6.2
Description
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:
java.lang.IllegalArgumentException: Invalid path string "//a_test" caused by empty node name specified @1
Solutions:
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; }
Attachments
Issue Links
- links to