[
https://issues.apache.org/jira/browse/ZOOKEEPER-2467?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15559137#comment-15559137
]
Rakesh R commented on ZOOKEEPER-2467:
-------------------------------------
Like [~fpj] mentioned earlier, it is good to assert the output/error message.
One idea is to redirect the err stream something similar to
{{ZooKeeperTest#testCliCommandsNotEchoingUsage}}.
How about something like,
{code}
// ZOOKEEPER-2467 : Testing negative number for redo command
@Test
public void testCliCommandHandleNegativeScenarioForRedoCmd()
throws Exception {
final ZooKeeper zk = createClient();
ZooKeeperMain zkMain = new ZooKeeperMain(zk);
String cmd1 = "redo -1";
// setup redirect out/err streams to get System.in/err, use this
// judiciously!
final PrintStream systemErr = System.err; // get current err
final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
System.setErr(new PrintStream(errContent));
try {
zkMain.executeLine(cmd1);
Assert.assertEquals("Command index out of range",
errContent.toString().trim());
} finally {
// revert redirect of out/err streams - important step!
System.setErr(systemErr);
}
}
{code}
> NullPointerException when redo Command is passed negative value
> ---------------------------------------------------------------
>
> Key: ZOOKEEPER-2467
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2467
> Project: ZooKeeper
> Issue Type: Bug
> Components: java client
> Affects Versions: 3.4.8, 3.5.2
> Environment: Linux , windows
> Reporter: Joshi Shankar
> Assignee: Rakesh Kumar Singh
> Priority: Minor
> Fix For: 3.4.10, 3.5.3
>
> Attachments: ZOOKEEPER-2467-1.patch, ZOOKEEPER-2467-final.patch,
> ZOOKEEPER-2467.patch, ZOOKEEPER-2467.patch, ZOOKEEPER-2467.patch
>
>
> When negative value of argument is passed to redo command .
> [zk: localhost:2181(CONNECTED) 0] redo -1
> Exception in thread "main" java.lang.NullPointerException
> at java.util.StringTokenizer.<init>(Unknown Source)
> at java.util.StringTokenizer.<init>(Unknown Source)
> at
> org.apache.zookeeper.ZooKeeperMain$MyCommandOptions.parseCommand(ZooKeeperMain.java:227)
> at
> org.apache.zookeeper.ZooKeeperMain.processZKCmd(ZooKeeperMain.java:645)
> at
> org.apache.zookeeper.ZooKeeperMain.processCmd(ZooKeeperMain.java:588)
> at
> org.apache.zookeeper.ZooKeeperMain.executeLine(ZooKeeperMain.java:360)
> at org.apache.zookeeper.ZooKeeperMain.run(ZooKeeperMain.java:323)
> at org.apache.zookeeper.ZooKeeperMain.main(ZooKeeperMain.java:282)
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)