cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject git commit: Fix NPE when using collections in frozen tuple
Date Wed, 03 Sep 2014 17:02:05 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1.0 82136e3b7 -> cf76ac66a


Fix NPE when using collections in frozen tuple

patch by omichallat; reviewed by slebresne for CASSANDRA-7869


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

Branch: refs/heads/cassandra-2.1.0
Commit: cf76ac66af4344acaaf44f8dec3ef584cff79bf2
Parents: 82136e3
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed Sep 3 19:01:20 2014 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Wed Sep 3 19:01:20 2014 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  4 ++
 .../org/apache/cassandra/cql3/CQL3Type.java     |  3 +-
 .../apache/cassandra/cql3/TupleTypeTest.java    | 39 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/cf76ac66/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b33bec4..93d77c1 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,7 @@
+2.1.0
+ * Add null check for keys when freezing collection (CASSANDRA-7869)
+
+
 2.1.0-rc7
  * Add frozen keyword and require UDT to be frozen (CASSANDRA-7857)
  * Track added sstable size correctly (CASSANDRA-7239)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cf76ac66/src/java/org/apache/cassandra/cql3/CQL3Type.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/CQL3Type.java b/src/java/org/apache/cassandra/cql3/CQL3Type.java
index 1589d6a..bb3bc62 100644
--- a/src/java/org/apache/cassandra/cql3/CQL3Type.java
+++ b/src/java/org/apache/cassandra/cql3/CQL3Type.java
@@ -404,7 +404,8 @@ public interface CQL3Type
 
             public Raw freeze()
             {
-                keys.freeze();
+                if (keys != null)
+                    keys.freeze();
                 values.freeze();
                 return super.freeze();
             }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cf76ac66/test/unit/org/apache/cassandra/cql3/TupleTypeTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/TupleTypeTest.java b/test/unit/org/apache/cassandra/cql3/TupleTypeTest.java
index 4ce24f8..f8771c1 100644
--- a/test/unit/org/apache/cassandra/cql3/TupleTypeTest.java
+++ b/test/unit/org/apache/cassandra/cql3/TupleTypeTest.java
@@ -100,4 +100,43 @@ public class TupleTypeTest extends CQLTester
     {
         assertInvalid("CREATE TABLE wrong (k int PRIMARY KEY, v tuple<int, text>)");
     }
+
+    @Test
+    public void testFrozenTupleWithList() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k int PRIMARY KEY, t frozen<tuple<text, list<int>>>)");
+
+        execute("INSERT INTO %s (k, t) VALUES (?, ?)", 0, tuple("foo", list(2, 1)));
+        execute("INSERT INTO %s (k, t) VALUES (?, ?)", 1, tuple("bar", list(3, 4)));
+        assertAllRows(
+            row(0, tuple("foo", list(2, 1))),
+            row(1, tuple("bar", list(3, 4)))
+        );
+    }
+
+    @Test
+    public void testFrozenTupleWithSet() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k int PRIMARY KEY, t frozen<tuple<text, set<int>>>)");
+
+        execute("INSERT INTO %s (k, t) VALUES (?, ?)", 0, tuple("foo", set(2, 1)));
+        execute("INSERT INTO %s (k, t) VALUES (?, ?)", 1, tuple("bar", set(3, 4)));
+        assertAllRows(
+            row(0, tuple("foo", set(2, 1))),
+            row(1, tuple("bar", set(3, 4)))
+        );
+    }
+
+    @Test
+    public void testFrozenTupleWithMap() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k int PRIMARY KEY, t frozen<tuple<text, map<int,
int>>>)");
+
+        execute("INSERT INTO %s (k, t) VALUES (?, ?)", 0, tuple("foo", map(2, 1)));
+        execute("INSERT INTO %s (k, t) VALUES (?, ?)", 1, tuple("bar", map(3, 4)));
+        assertAllRows(
+            row(0, tuple("foo", map(2, 1))),
+            row(1, tuple("bar", map(3, 4)))
+        );
+    }
 }


Mime
View raw message