Skip to content

Commit 447fa4f

Browse files
authored
ESQL: Fix NPE on empty to_lower/to_upper call (#131917) (#131924)
Apparently, when calling to_lower or to_upper with no parameters, an NPE was thrown, instead of a proper error. AFAICT, this is an old left-over from when these functions were imported from a much older version. Resolves #131913.
1 parent 21d2a72 commit 447fa4f

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

docs/changelog/131917.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 131917
2+
summary: Fix NPE on empty to_lower/to_upper call
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 131913

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,10 +1129,10 @@ public static <T extends Function> FunctionDefinition def(
11291129
String... names
11301130
) {
11311131
FunctionBuilder builder = (source, children, cfg) -> {
1132-
if (children.size() > 1) {
1132+
if (children.size() != 1) {
11331133
throw new QlIllegalArgumentException("expects exactly one argument");
11341134
}
1135-
Expression ex = children.size() == 1 ? children.get(0) : null;
1135+
Expression ex = children.get(0);
11361136
return ctorRef.build(source, ex, cfg);
11371137
};
11381138
return def(function, builder, names);

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistryTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public void testConfigurationOptionalFunction() {
159159
);
160160
def = r.resolveFunction(r.resolveAlias("DUMMY"));
161161
assertEquals(ur.source(), ur.buildResolved(randomConfiguration(), def).source());
162+
163+
ParsingException e = expectThrows(ParsingException.class, () -> uf(DEFAULT).buildResolved(randomConfiguration(), def));
164+
assertThat(e.getMessage(), containsString("expects exactly one argument"));
162165
}
163166

164167
private static UnresolvedFunction uf(FunctionResolutionStrategy resolutionStrategy, Expression... children) {

0 commit comments

Comments
 (0)