cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject cassandra git commit: Fix AIOOBE when building syntax error message
Date Fri, 12 Dec 2014 18:07:17 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 c3ac6baac -> 254d6f7e9


Fix AIOOBE when building syntax error message

Patch by Benjamin Lerer; reviewed by Tyler Hobbs for CASSANDRA-8455


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

Branch: refs/heads/cassandra-2.1
Commit: 254d6f7e9c689c639f85f3f5119f4a812d295f05
Parents: c3ac6ba
Author: blerer <b_lerer@hotmail.com>
Authored: Fri Dec 12 12:02:40 2014 -0600
Committer: Tyler Hobbs <tyler@datastax.com>
Committed: Fri Dec 12 12:03:34 2014 -0600

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../apache/cassandra/cql3/ErrorCollector.java   | 30 ++++++++++++++++++++
 .../apache/cassandra/cql3/QueryProcessor.java   |  1 +
 .../cassandra/cql3/ErrorCollectorTest.java      | 17 +++++++++++
 4 files changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/254d6f7e/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5402ad5..07d526c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 2.1.3
+ * Fix ArrayIndexOutOfBoundsException when generating error message
+   for some CQL syntax errors (CASSANDRA-8455)
  * Scale memtable slab allocation logarithmically (CASSANDRA-7882)
  * cassandra-stress simultaneous inserts over same seed (CASSANDRA-7964)
  * Reduce cassandra-stress sampling memory requirements (CASSANDRA-7926)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/254d6f7e/src/java/org/apache/cassandra/cql3/ErrorCollector.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/ErrorCollector.java b/src/java/org/apache/cassandra/cql3/ErrorCollector.java
index cd628b8..2137da2 100644
--- a/src/java/org/apache/cassandra/cql3/ErrorCollector.java
+++ b/src/java/org/apache/cassandra/cql3/ErrorCollector.java
@@ -132,6 +132,9 @@ public final class ErrorCollector implements ErrorListener
                              Token to,
                              Token offending)
     {
+        if (!areTokensValid(from, to, offending))
+            return;
+
         String[] lines = query.split("\n");
 
         boolean includeQueryStart = (from.getLine() == 1) && (from.getCharPositionInLine()
== 0);
@@ -157,6 +160,33 @@ public final class ErrorCollector implements ErrorListener
     }
 
     /**
+     * Checks if the specified tokens are valid.
+     *
+     * @param tokens the tokens to check
+     * @return <code>true</code> if all the specified tokens are valid ones,
<code>false</code> otherwise.
+     */
+    private static boolean areTokensValid(Token... tokens)
+    {
+        for (Token token : tokens)
+        {
+            if (!isTokenValid(token))
+                return false;
+        }
+        return true;
+    }
+
+    /**
+     * Checks that the specified token is valid.
+     *
+     * @param token the token to check
+     * @return <code>true</code> if it is considered as valid, <code>false</code>
otherwise.
+     */
+    private static boolean isTokenValid(Token token)
+    {
+        return token.getLine() > 0 && token.getCharPositionInLine() >= 0;
+    }
+
+    /**
      * Returns the index of the offending token. <p>In the case where the offending
token is an extra
      * character at the end, the index returned by the <code>TokenStream</code>
might be after the last token.
      * To avoid that problem we need to make sure that the index of the offending token is
a valid index 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/254d6f7e/src/java/org/apache/cassandra/cql3/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
index 8e829e8..197225b 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -542,6 +542,7 @@ public class QueryProcessor implements QueryHandler
         }
         catch (RuntimeException re)
         {
+            logger.error(String.format("The statement: [%s] could not be parsed.", queryStr),
re);
             throw new SyntaxException(String.format("Failed parsing statement: [%s] reason:
%s %s",
                                                     queryStr,
                                                     re.getClass().getSimpleName(),

http://git-wip-us.apache.org/repos/asf/cassandra/blob/254d6f7e/test/unit/org/apache/cassandra/cql3/ErrorCollectorTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ErrorCollectorTest.java b/test/unit/org/apache/cassandra/cql3/ErrorCollectorTest.java
index 4f5db34..fca93df 100644
--- a/test/unit/org/apache/cassandra/cql3/ErrorCollectorTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ErrorCollectorTest.java
@@ -107,6 +107,23 @@ public class ErrorCollectorTest
         assertEquals(expected, builder.toString());
     }
 
+    @Test
+    public void testAppendSnippetWithInvalidToToken()
+    {
+        String query = "CREATE TABLE test (a int PRIMARY KEY, b set<int>;";
+
+        ErrorCollector collector = new ErrorCollector(query);
+
+        StringBuilder builder = new StringBuilder();
+
+        Token from = new MockToken(1, 32, " ");
+        Token to = new MockToken(0, -1, "<no text>");
+        Token offending = new MockToken(1, 48, ";");
+
+        collector.appendSnippet(builder, from, to, offending);
+        assertEquals("", builder.toString());
+    }
+
     private final static class MockToken implements Token
     {
         /**


Mime
View raw message