Fix NPE in nodetool compactionhistory

patch by Pierre N. and yukim; reviewed by yukim for CASSANDRA-9758
This commit is contained in:
Yuki Morishita 2015-09-16 08:36:50 -05:00
parent 4b1d59e131
commit 588dc06eb8
3 changed files with 34 additions and 2 deletions

View File

@ -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)

View File

@ -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);
}

View File

@ -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
{