You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by yu...@apache.org on 2015/09/16 15:47:44 UTC

[03/10] cassandra git commit: Fix NPE in nodetool compactionhistory

Fix NPE in nodetool compactionhistory

patch by Pierre N. and yukim; reviewed by yukim for CASSANDRA-9758


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/588dc06e
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/588dc06e
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/588dc06e

Branch: refs/heads/cassandra-3.0
Commit: 588dc06eb8b5a7678128e9f0c0421fc391b14bce
Parents: 4b1d59e
Author: Yuki Morishita <yu...@apache.org>
Authored: Wed Sep 16 08:36:50 2015 -0500
Committer: Yuki Morishita <yu...@apache.org>
Committed: Wed Sep 16 08:36:50 2015 -0500

----------------------------------------------------------------------
 CHANGES.txt                                      |  1 +
 .../org/apache/cassandra/utils/FBUtilities.java  | 16 ++++++++++++++--
 .../apache/cassandra/utils/FBUtilitiesTest.java  | 19 +++++++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/588dc06e/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 12523be..2787739 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.10
+ * Fix NPE in nodetool compactionhistory (CASSANDRA-9758)
  * (Pig) support BulkOutputFormat as a URL parameter (CASSANDRA-7410)
  * BATCH statement is broken in cqlsh (CASSANDRA-10272)
  * Added configurable warning threshold for GC duration (CASSANDRA-8907)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/588dc06e/src/java/org/apache/cassandra/utils/FBUtilities.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/FBUtilities.java b/src/java/org/apache/cassandra/utils/FBUtilities.java
index 214f2f5..f866610 100644
--- a/src/java/org/apache/cassandra/utils/FBUtilities.java
+++ b/src/java/org/apache/cassandra/utils/FBUtilities.java
@@ -28,7 +28,6 @@ import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.text.NumberFormat;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -36,6 +35,9 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.zip.Checksum;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 import com.google.common.base.Joiner;
 import com.google.common.collect.AbstractIterator;
 import org.apache.cassandra.io.util.FileUtils;
@@ -472,8 +474,18 @@ public class FBUtilities
         return s;
     }
 
-    public static String toString(Map<?,?> map)
+    /**
+     * Make straing out of the given {@code Map}.
+     *
+     * @param map Map to make string.
+     * @return String representation of all entries in the map,
+     *         where key and value pair is concatenated with ':'.
+     */
+    @Nonnull
+    public static String toString(@Nullable Map<?, ?> map)
     {
+        if (map == null)
+            return "";
         Joiner.MapJoiner joiner = Joiner.on(", ").withKeyValueSeparator(":");
         return joiner.join(map);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/588dc06e/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java b/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java
index adf3763..c82bcc9 100644
--- a/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java
+++ b/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java
@@ -27,6 +27,11 @@ import java.nio.charset.StandardCharsets;
 import com.google.common.primitives.Ints;
 import org.junit.Test;
 
+import java.util.Map;
+import java.util.TreeMap;
+
+import static org.junit.Assert.assertEquals;
+
 public class FBUtilitiesTest
 {
     @Test
@@ -70,6 +75,20 @@ public class FBUtilitiesTest
         }
     }
 
+    @Test
+    public void testToString()
+    {
+        // null turns to empty string
+        assertEquals("", FBUtilities.toString(null));
+        Map<String, String> map = new TreeMap<>();
+        // empty map turns to empty string
+        assertEquals("", FBUtilities.toString(map));
+        map.put("aaa", "bbb");
+        assertEquals("aaa:bbb", FBUtilities.toString(map));
+        map.put("ccc", "ddd");
+        assertEquals("aaa:bbb, ccc:ddd", FBUtilities.toString(map));
+    }
+
     @Test(expected=CharacterCodingException.class)
     public void testDecode() throws IOException
     {