You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@zookeeper.apache.org by "Reno Shen (Jira)" <ji...@apache.org> on 2021/06/23 07:55:00 UTC

[jira] [Updated] (ZOOKEEPER-4325) IllegalArgumentException when use ZkUtil::listSubTreeBFS to list "/"

     [ https://issues.apache.org/jira/browse/ZOOKEEPER-4325?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Reno Shen updated ZOOKEEPER-4325:
---------------------------------
    Description: 
[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 + "/" + child).replace("//", "/");
            queue.add(childPath);
            tree.add(childPath);
        }
    }
    return tree;
}
{code}

  was:
[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}
 

 


> 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
>             Fix For: 3.6.2
>
>
> [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 + "/" + child).replace("//", "/");
>             queue.add(childPath);
>             tree.add(childPath);
>         }
>     }
>     return tree;
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)