Skip to content

Commit

Permalink
Throw semantic exception when '?' is passed for parameter
Browse files Browse the repository at this point in the history
Used to throw NullPointerException
  • Loading branch information
kasiafi authored and martint committed Jul 24, 2020
1 parent 063a747 commit 02c5bf1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,11 @@ protected Type visitParameter(Parameter node, StackableAstVisitorContext<Context
throw semanticException(INVALID_PARAMETER_USAGE, node, "Invalid parameter index %s, max value is %s", node.getPosition(), parameters.size() - 1);
}

Type resultType = process(parameters.get(NodeRef.of(node)), context);
Expression providedValue = parameters.get(NodeRef.of(node));
if (providedValue == null) {
throw semanticException(INVALID_PARAMETER_USAGE, node, "No value provided for parameter");
}
Type resultType = process(providedValue, context);
return setExpressionType(node, resultType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,20 @@ public void testParametersNonPreparedStatement()
"line 1:1: Incorrect number of parameters: expected 1 but found 0");
}

@Test
public void testParameterInParameter()
{
String query = "SELECT a FROM (VALUES 1) t(a) where a = ?";
Session session = Session.builder(getSession())
.addPreparedStatement("my_query", query)
.build();

assertQueryFails(
session,
"EXECUTE my_query USING ?",
"\\Qline 1:24: No value provided for parameter\\E");
}

@Test
public void testDescribeInput()
{
Expand Down

0 comments on commit 02c5bf1

Please sign in to comment.