Permalink
Browse files

Add check for nulls when creating a batch mutation

  • Loading branch information...
elandau committed Dec 21, 2012
1 parent d3e63e1 commit 8c71eab573d6d22feb06bd128dd0f5bb5a8c730f
@@ -23,6 +23,7 @@
import java.util.Set;
import java.util.Map.Entry;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Maps.EntryTransformer;
@@ -127,6 +128,9 @@ public AbstractThriftMutationBatchImpl(Clock clock, ConsistencyLevel consistency
@Override
public <K, C> ColumnListMutation<C> withRow(ColumnFamily<K, C> columnFamily, K rowKey) {
+ Preconditions.checkNotNull(columnFamily, "columnFamily cannot be null");
+ Preconditions.checkNotNull(rowKey, "Row key cannot be null");
+
if (clock != null && mutationMap.isEmpty())
this.timestamp = clock.getCurrentTime();
@@ -107,6 +107,7 @@ public ThriftCounterSuperColumnMutationImpl(long timestamp, List<Mutation> mutat
@Override
public ColumnListMutation<C> setDefaultTtl(Integer ttl) {
+ // TODO: Throw an exception
return this;
}
}
@@ -1926,6 +1926,21 @@ public void testFunctionalQuery() throws ConnectionException {
* 5) .execute();
*/
}
+
+ @Test
+ public void testNullKeyInMutation() throws ConnectionException {
+ try {
+ keyspace.prepareMutationBatch()
+ .withRow(CF_STANDARD1, null)
+ .putColumn("abc", "def");
+
+ Assert.fail();
+ }
+ catch (NullPointerException e) {
+
+ }
+ }
+
@Test
public void testColumnSlice() throws ConnectionException {

0 comments on commit 8c71eab

Please sign in to comment.