Skip to content

Commit

Permalink
ZOOKEEPER-1059. stat command isses on non-existing node causes NPE. (…
Browse files Browse the repository at this point in the history
…Bhallamudi Kamesh via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1103811 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Mahadev Konar committed May 16, 2011
1 parent 011c465 commit cda8d31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -211,6 +211,8 @@ BUGFIXES:

ZOOKEEPER-1061. Zookeeper stop fails if start called twice. (Ted Dunning via mahadev)

ZOOKEEPER-1059. stat command isses on non-existing node causes NPE. (Bhallamudi Kamesh via mahadev)

IMPROVEMENTS:
ZOOKEEPER-724. Improve junit test integration - log harness information
(phunt via mahadev)
Expand Down
5 changes: 4 additions & 1 deletion src/java/main/org/apache/zookeeper/ZooKeeperMain.java
Expand Up @@ -147,7 +147,7 @@ private static void printStat(Stat stat) {
* A storage class for both command line options and shell commands.
*
*/
static private class MyCommandOptions {
static class MyCommandOptions {

private Map<String,String> options = new HashMap<String,String>();
private List<String> cmdArgs = null;
Expand Down Expand Up @@ -724,6 +724,9 @@ protected boolean processZKCmd(MyCommandOptions co)
} else if (cmd.equals("stat") && args.length >= 2) {
path = args[1];
stat = zk.exists(path, watch);
if (stat == null) {
throw new KeeperException.NoNodeException(path);
}
printStat(stat);
} else if (cmd.equals("listquota") && args.length >= 2) {
path = args[1];
Expand Down
15 changes: 15 additions & 0 deletions src/java/test/org/apache/zookeeper/ZooKeeperTest.java
Expand Up @@ -122,4 +122,19 @@ public void processResult(int rc, String path, Object ctx) {
}
Assert.assertEquals(4, ((AtomicInteger) ctx).get());
}

@Test
public void testStatWhenPathDoesNotExist() throws IOException,
InterruptedException {
final ZooKeeper zk = createClient();
ZooKeeperMain main = new ZooKeeperMain(zk);
String cmdstring = "stat /invalidPath";
main.cl.parseCommand(cmdstring);
try {
main.processZKCmd(main.cl);
Assert.fail("As Node does not exist, command should fail by throwing No Node Exception.");
} catch (KeeperException e) {
Assert.assertEquals("KeeperErrorCode = NoNode for /invalidPath", e.getMessage());
}
}
}

0 comments on commit cda8d31

Please sign in to comment.