Repository: zookeeper
Updated Branches:
  refs/heads/branch-3.4 8bb13ba2f -> a601b0329


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/a601b032
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/a601b032
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/a601b032

Branch: refs/heads/branch-3.4
Commit: a601b032915e85a5f693e7ef247700fefb950a12
Parents: 8bb13ba
Author: Rakesh Radhakrishnan <rake...@apache.org>
Authored: Sun Oct 16 18:29:41 2016 +0530
Committer: Rakesh Radhakrishnan <rake...@apache.org>
Committed: Sun Oct 16 18:29:41 2016 +0530

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


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/a601b032/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index f0e7799..f66378d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -14,6 +14,9 @@ BUGFIXES:
   ZOOKEEPER-2579: ZooKeeper server should verify that dataDir and
   snapDir are writeable before starting (Abraham Fine via phunt)
 
+  ZOOKEEPER-2467: NullPointerException when redo Command is passed negative 
value
+  (Rakesh Kumar Singh via rakeshr)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-2507: C unit test improvement: line break between

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/a601b032/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 baf1c49..26721f5 100644
--- a/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
+++ b/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
@@ -649,7 +649,7 @@ public class ZooKeeperMain {
             System.exit(0);
         } 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
                 System.out.println("Command index out of range");
                 return false;
             }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/a601b032/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 d75a817..2cdc4cb 100644
--- a/src/java/test/org/apache/zookeeper/ZooKeeperTest.java
+++ b/src/java/test/org/apache/zookeeper/ZooKeeperTest.java
@@ -255,4 +255,27 @@ public class ZooKeeperTest extends ClientBase {
         Assert.assertEquals("empty string is not taken as third argument", 
zkMain.cl.getCmdArgument(2), "");
         Assert.assertEquals("empty string is not taken as fourth argument", 
zkMain.cl.getCmdArgument(3), "");
     }
+
+    // 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 systemOut = System.out; // get current out
+        final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+        System.setOut(new PrintStream(outContent));
+        try {
+            zkMain.executeLine(cmd1);
+            Assert.assertEquals("Command index out of range", outContent
+                    .toString().trim());
+        } finally {
+            // revert redirect of out/err streams - important step!
+            System.setOut(systemOut);
+        }
+    }
+
 }

Reply via email to