You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ty...@apache.org on 2014/08/06 00:21:09 UTC

git commit: Avoid IOOBE when building SyntaxError message snippet

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 91d61b327 -> 72241f6d7


Avoid IOOBE when building SyntaxError message snippet

Patch by Benjamin Lerer; review by Tyler Hobbs for CASSANDRA-7569


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

Branch: refs/heads/cassandra-2.1
Commit: 72241f6d725f9c69f1bd5239c798f1676d00ec16
Parents: 91d61b3
Author: blerer <b_...@hotmail.com>
Authored: Tue Aug 5 17:20:20 2014 -0500
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Tue Aug 5 17:20:20 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                        |  1 +
 .../org/apache/cassandra/cql3/ErrorCollector.java  | 17 ++++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/72241f6d/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 79c84b2..9ef6cc3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.1
+ * Avoid IOOBE when building SyntaxError message snippet (CASSANDRA-7569)
  * SSTableExport uses correct validator to create string representation of partition
    keys (CASSANDRA-7498)
  * Avoid NPEs when receiving type changes for an unknown keyspace (CASSANDRA-7689)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/72241f6d/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 41536f5..cd628b8 100644
--- a/src/java/org/apache/cassandra/cql3/ErrorCollector.java
+++ b/src/java/org/apache/cassandra/cql3/ErrorCollector.java
@@ -115,7 +115,7 @@ public final class ErrorCollector implements ErrorListener
 
         Token from = tokenStream.get(getSnippetFirstTokenIndex(index));
         Token to = tokenStream.get(getSnippetLastTokenIndex(index, size));
-        Token offending = tokenStream.get(index);
+        Token offending = tokenStream.get(getOffendingTokenIndex(index, size));
 
         appendSnippet(builder, from, to, offending);
     }
@@ -157,6 +157,21 @@ public final class ErrorCollector implements ErrorListener
     }
 
     /**
+     * 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 
+     * (one for which a token exist).</p>
+     *
+     * @param index the token index returned by the <code>TokenStream</code>
+     * @param size the <code>TokenStream</code> size
+     * @return the valid index of the offending token
+     */
+    private static int getOffendingTokenIndex(int index, int size)
+    {
+        return Math.min(index, size - 1);
+    }
+
+    /**
      * Puts the specified token within square brackets.
      *
      * @param line the line containing the token