Repository: zookeeper
Updated Branches:
  refs/heads/branch-3.5 d53501b09 -> 3cd87f069


ZOOKEEPER-2467: NullPointerException when redo Command is passed negative value 
(Rakesh Kumar Singh via rakeshr)


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/3cd87f06
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/3cd87f06
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/3cd87f06

Branch: refs/heads/branch-3.5
Commit: 3cd87f06911c6fd806364bf46ae074e7c6096452
Parents: d53501b
Author: Rakesh Radhakrishnan <rake...@apache.org>
Authored: Sun Oct 16 18:08:34 2016 +0530
Committer: Rakesh Radhakrishnan <rake...@apache.org>
Committed: Sun Oct 16 18:08:34 2016 +0530

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 +++
 .../org/apache/zookeeper/ZooKeeperMain.java     |  2 +-
 .../org/apache/zookeeper/ZooKeeperTest.java     | 22 ++++++++++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3cd87f06/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 67c613d..b6ab85b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -68,6 +68,9 @@ BUGFIXES:
   ZOOKEEPER-2611: zoo_remove_watchers - can remove the wrong watch
   (Eyal Leshmem via rgs)
 
+  ZOOKEEPER-2467: NullPointerException when redo Command is passed negative 
value
+  (Rakesh Kumar Singh via rakeshr)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-2505: Use shared library instead of static library in C

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3cd87f06/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/ZooKeeperMain.java 
b/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
index 25d61a4..c39395a 100644
--- a/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
+++ b/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
@@ -616,7 +616,7 @@ public class ZooKeeperMain {
             System.exit(exitCode);
         } else if (cmd.equals("redo") && args.length >= 2) {
             Integer i = Integer.decode(args[1]);
-            if (commandCount <= i) { // don't allow redoing this redo
+            if (commandCount <= i || i < 0) { // don't allow redoing this redo
                 throw new MalformedCommandException("Command index out of 
range");
             }
             cl.parseCommand(history.get(i));

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3cd87f06/src/java/test/org/apache/zookeeper/ZooKeeperTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/ZooKeeperTest.java 
b/src/java/test/org/apache/zookeeper/ZooKeeperTest.java
index 8ff98bd..dd610dd 100644
--- a/src/java/test/org/apache/zookeeper/ZooKeeperTest.java
+++ b/src/java/test/org/apache/zookeeper/ZooKeeperTest.java
@@ -433,6 +433,28 @@ public class ZooKeeperTest extends ClientBase {
         }
     }
 
+    // ZOOKEEPER-2467 : Testing negative number for redo command
+    @Test
+    public void testRedoWithNegativeCmdNumber() 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);
+        }
+    }
+
     private static void runCommandExpect(CliCommand command, List<String> 
expectedResults)
             throws Exception {
         // call command and put result in byteStream

Reply via email to