Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #446 from jancona/composite-empty-string

Fix round-tripping of empty String Component in Composite
  • Loading branch information...
commit 0666efae571e18924c93efff4d9027772b887b5f 2 parents 40fa574 + 98435e5
@edanuff edanuff authored
View
8 core/src/main/java/me/prettyprint/hector/api/beans/AbstractComposite.java
@@ -142,9 +142,7 @@ public Component(T value, ByteBuffer bytes, Serializer<T> serializer,
}
if ((value == null) && (bytes != null) && (s != null)) {
ByteBuffer cb = bytes.duplicate();
- if (cb.hasRemaining()) {
- return s.fromByteBuffer(cb);
- }
+ return s.fromByteBuffer(cb);
}
if (value instanceof ByteBuffer) {
return (A) ((ByteBuffer) value).duplicate();
@@ -457,6 +455,10 @@ public int size() {
Serializer<T> s, String comparator, ComponentEquality equality) {
serialized = null;
+ if (value == null) {
+ throw new NullPointerException("Unable able to add null component");
+ }
+
if (index < 0) {
index = components.size();
}
View
31 core/src/test/java/me/prettyprint/hector/api/CompositeTest.java
@@ -2,8 +2,8 @@
import static me.prettyprint.hector.api.ddl.ComparatorType.UUIDTYPE;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.math.BigInteger;
import java.nio.ByteBuffer;
@@ -14,7 +14,6 @@
import me.prettyprint.cassandra.serializers.BigIntegerSerializer;
import me.prettyprint.cassandra.serializers.ByteBufferSerializer;
-import me.prettyprint.cassandra.serializers.DynamicCompositeSerializer;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.serializers.UUIDSerializer;
import me.prettyprint.cassandra.utils.TimeUUIDUtils;
@@ -161,15 +160,11 @@ public void testNullValueSerialization() throws Exception {
// test correct serialization with null values and user specified
// serialization
DynamicComposite c = new DynamicComposite();
- c.addComponent(null, StringSerializer.get());
-
- DynamicCompositeSerializer serializer = new DynamicCompositeSerializer();
-
- ByteBuffer buff = serializer.toByteBuffer(c);
-
- DynamicComposite result = serializer.fromByteBuffer(buff);
-
- assertNull(result.get(0));
+ try {
+ c.addComponent(null, StringSerializer.get());
+ fail("Null values not allowed");
+ } catch (NullPointerException e) {
+ }
}
@Test
@@ -187,6 +182,20 @@ public void testStaticSerialization() throws Exception {
}
@Test
+ public void testEmptyStringSerialization() throws Exception {
+
+ ByteBuffer b = createCompositeKey("",
+ TimeUUIDUtils.getUniqueTimeUUIDinMillis(), 10, false);
+ Composite c = new Composite();
+ c.setSerializersByPosition(StringSerializer.get(), UUIDSerializer.get(),
+ BigIntegerSerializer.get());
+ c.deserialize(b.slice());
+ assertTrue(c.get(0) instanceof String);
+ assertTrue(c.get(1) instanceof UUID);
+ assertTrue(c.get(2) instanceof BigInteger);
+ }
+
+ @Test
public void testEquality() throws Exception {
DynamicCompositeType instance = getDefaultDynamicComparator();
Please sign in to comment.
Something went wrong with that request. Please try again.