You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sn...@apache.org on 2015/06/22 16:52:05 UTC

[08/16] cassandra git commit: 'WITH WITH' in alter keyspace statements causes NPE

'WITH WITH' in alter keyspace statements causes NPE

patch by Benjamin Lerer; reviewed by Robert Stupp for CASSANDRA-9565


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

Branch: refs/heads/trunk
Commit: c939422637bdba13fa3b5849cc1e7eacf26d46d0
Parents: f778c1f
Author: Benjamin Lerer <bl...@datastax.com>
Authored: Mon Jun 22 16:40:36 2015 +0200
Committer: Robert Stupp <sn...@snazy.de>
Committed: Mon Jun 22 16:40:36 2015 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 src/java/org/apache/cassandra/cql3/Cql.g        |  4 +-
 .../cql3/CreateAndAlterKeyspaceTest.java        | 89 ++++++++++++++++++++
 3 files changed, 92 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9394226/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b5b2f32..6e3a147 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.0.17
+ * 'WITH WITH' in alter keyspace statements causes NPE (CASSANDRA-9565)
  * Display min timestamp in sstablemetadata viewer (CASSANDRA-6767)
 
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9394226/src/java/org/apache/cassandra/cql3/Cql.g
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g
index d41434d..8b382fa 100644
--- a/src/java/org/apache/cassandra/cql3/Cql.g
+++ b/src/java/org/apache/cassandra/cql3/Cql.g
@@ -891,8 +891,8 @@ properties[PropertyDefinitions props]
     ;
 
 property[PropertyDefinitions props]
-    : k=ident '=' (simple=propertyValue { try { $props.addProperty(k.toString(), simple); } catch (SyntaxException e) { addRecognitionError(e.getMessage()); } }
-                   |   map=map_literal   { try { $props.addProperty(k.toString(), convertPropertyMap(map)); } catch (SyntaxException e) { addRecognitionError(e.getMessage()); } })
+    : k=ident '=' simple=propertyValue { try { $props.addProperty(k.toString(), simple); } catch (SyntaxException e) { addRecognitionError(e.getMessage()); } }
+    | k=ident '=' map=map_literal { try { $props.addProperty(k.toString(), convertPropertyMap(map)); } catch (SyntaxException e) { addRecognitionError(e.getMessage()); } }
     ;
 
 propertyValue returns [String str]

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9394226/test/unit/org/apache/cassandra/cql3/CreateAndAlterKeyspaceTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/CreateAndAlterKeyspaceTest.java b/test/unit/org/apache/cassandra/cql3/CreateAndAlterKeyspaceTest.java
new file mode 100644
index 0000000..45be0df
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/CreateAndAlterKeyspaceTest.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.cql3;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.db.ConsistencyLevel;
+import org.apache.cassandra.exceptions.SyntaxException;
+import org.apache.cassandra.gms.Gossiper;
+
+import static org.apache.cassandra.cql3.QueryProcessor.process;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class CreateAndAlterKeyspaceTest
+{
+    @BeforeClass
+    public static void setUpClass() throws Throwable
+    {
+        SchemaLoader.loadSchema();
+    }
+
+    @AfterClass
+    public static void stopGossiper()
+    {
+        Gossiper.instance.stop();
+    }
+
+    @Test
+    // tests CASSANDRA-9565
+    public void testCreateAndAlterWithDoubleWith() throws Throwable
+    {
+        String[] stmts = new String[] {"ALTER KEYSPACE WITH WITH DURABLE_WRITES = true",
+                                       "ALTER KEYSPACE ks WITH WITH DURABLE_WRITES = true",
+                                       "CREATE KEYSPACE WITH WITH DURABLE_WRITES = true",
+                                       "CREATE KEYSPACE ks WITH WITH DURABLE_WRITES = true"};
+
+        for (String stmt : stmts) {
+            assertInvalidSyntax(stmt, "no viable alternative at input 'WITH'");
+        }
+    }
+
+    /**
+     * Checks that the specified statement result in a <code>SyntaxException</code> containing the specified message.
+     *
+     * @param stmt the statement to check
+     */
+    private static void assertInvalidSyntax(String stmt, String msg) throws Throwable {
+        try {
+            process(stmt, ConsistencyLevel.ONE);
+            fail();
+        } catch (RuntimeException e) {
+            assertSyntaxException(e.getCause(), msg);
+        }
+    }
+
+    /**
+     * Asserts that the specified exception is a <code>SyntaxException</code> for which the error message contains
+     * the specified text.
+     *
+     * @param exception the exception to test
+     * @param expectedContent the expected content of the error message
+     */
+    private static void assertSyntaxException(Throwable exception, String expectedContent) {
+        assertTrue("The exception should be a SyntaxException but is not", exception instanceof SyntaxException);
+
+        String msg = exception.getMessage();
+        assertTrue(String.format("The error message was expected to contains: %s but was %s", expectedContent, msg),
+                   msg.contains(expectedContent));
+    }
+}