Skip to content

Commit 32e251f

Browse files
ES|QL: fix NPE with null field parameter (elastic#142328) (elastic#142372)
1 parent 8d3b485 commit 32e251f

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

docs/changelog/142328.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
area: ES|QL
2+
issues:
3+
- 142281
4+
pr: 142328
5+
summary: Fix NPE with null field parameter
6+
type: bug

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ExpressionBuilder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,10 @@ private Expression visitDoubleParam(EsqlBaseParser.DoubleParameterContext ctx, Q
12961296
)
12971297
);
12981298
}
1299-
return new UnresolvedAttribute(source(ctx), param.value().toString());
1299+
if (param.value() == null) {
1300+
context.params.addParsingError(new ParsingException(source(ctx), "Query parameter [{}] is null", ctx.getText()));
1301+
}
1302+
return new UnresolvedAttribute(source(ctx), String.valueOf(param.value()));
13001303
}
13011304

13021305
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/ParamsParserTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,22 @@ public void testInvalidDoubleParamsType() {
823823
}
824824
}
825825

826+
public void testNullDoubleParamsValue() {
827+
assumeTrue("double parameters markers for identifiers", EsqlCapabilities.Cap.DOUBLE_PARAMETER_MARKERS_FOR_IDENTIFIERS.isEnabled());
828+
String error = "Query parameter [??f1] is null";
829+
List<String> commandWithDoubleParams = List.of(
830+
"eval x = ??f1",
831+
"stats x = count(??f1)",
832+
"sort ??f1",
833+
"keep ??f1",
834+
"drop ??f1",
835+
"mv_expand ??f1"
836+
);
837+
for (String command : commandWithDoubleParams) {
838+
expectError("from test | " + command, List.of(paramAsConstant("f1", null)), error);
839+
}
840+
}
841+
826842
public void testLikeParam() {
827843
if (EsqlCapabilities.Cap.LIKE_PARAMETER_SUPPORT.isEnabled()) {
828844
LogicalPlan anonymous = query(

0 commit comments

Comments
 (0)