Updated Branches:
  refs/heads/trunk 0b20e139d -> b2a949ecd

Fix NPE during cql3 select with token()

patch by slebresne; reviewed by driftx for CASSANDRA-5404


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

Branch: refs/heads/trunk
Commit: b82027ccbc315bfd46f760204c71358e5f85b254
Parents: 65b9093
Author: Sylvain Lebresne <sylv...@datastax.com>
Authored: Tue Apr 2 19:22:48 2013 +0200
Committer: Sylvain Lebresne <sylv...@datastax.com>
Committed: Tue Apr 2 19:22:48 2013 +0200

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../cassandra/cql3/functions/FunctionCall.java     |    6 +++++-
 .../cassandra/cql3/statements/Selection.java       |    2 ++
 3 files changed, 8 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b82027cc/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index c7d64b4..727ede8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -16,6 +16,7 @@
  * Fix streaming compressed files when using encryption (CASSANDRA-5391)
  * cassandra-all 1.2.0 pom missing netty dependency (CASSANDRA-5392)
  * Fix writetime/ttl functions on null values (CASSANDRA-5341)
+ * Fix NPE during cql3 select with token() (CASSANDRA-5404)
 Merged from 1.1:
  * cli: Quote ks and cf names in schema output when needed (CASSANDRA-5052)
  * Fix bad default for min/max timestamp in SSTableMetadata (CASSANDRA-5372)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b82027cc/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java 
b/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
index 01c26af..14a9b78 100644
--- a/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
+++ b/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
@@ -132,7 +132,11 @@ public class FunctionCall extends Term.NonTerminal
         public boolean isAssignableTo(ColumnSpecification receiver)
         {
             AbstractType<?> returnType = Functions.getReturnType(functionName, 
receiver.ksName, receiver.cfName);
-            return receiver.type.asCQL3Type().equals(returnType.asCQL3Type());
+            // Note: if returnType == null, it means the function doesn't 
exist. We may get this if an undefined function
+            // is used as argument of another, existing, function. In that 
case, we return true here because we'll catch
+            // the fact that the method is undefined latter anyway and with a 
more helpful error message that if we were
+            // to return false here.
+            return returnType == null || 
receiver.type.asCQL3Type().equals(returnType.asCQL3Type());
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b82027cc/src/java/org/apache/cassandra/cql3/statements/Selection.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/Selection.java 
b/src/java/org/apache/cassandra/cql3/statements/Selection.java
index 983c35b..e4e59c5 100644
--- a/src/java/org/apache/cassandra/cql3/statements/Selection.java
+++ b/src/java/org/apache/cassandra/cql3/statements/Selection.java
@@ -117,6 +117,8 @@ public abstract class Selection
                 args.add(makeSelector(cfDef, rawArg, names, null));
 
             AbstractType<?> returnType = 
Functions.getReturnType(withFun.functionName, cfDef.cfm.ksName, 
cfDef.cfm.cfName);
+            if (returnType == null)
+                throw new InvalidRequestException(String.format("Unknown 
function '%s'", withFun.functionName));
             ColumnSpecification spec = makeFunctionSpec(cfDef, withFun, 
returnType);
             Function fun = Functions.get(withFun.functionName, args, spec);
             if (metadata != null)

Reply via email to