Skip to content

Commit 7534840

Browse files
authored
ESQL: Fix NPE on empty to_lower/to_upper call (#131917) (#131922)
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 e69a5eb commit 7534840

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-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
@@ -1042,10 +1042,10 @@ public static <T extends Function> FunctionDefinition def(
10421042
String... names
10431043
) {
10441044
FunctionBuilder builder = (source, children, cfg) -> {
1045-
if (children.size() > 1) {
1045+
if (children.size() != 1) {
10461046
throw new QlIllegalArgumentException("expects exactly one argument");
10471047
}
1048-
Expression ex = children.size() == 1 ? children.get(0) : null;
1048+
Expression ex = children.get(0);
10491049
return ctorRef.build(source, ex, cfg);
10501050
};
10511051
return def(function, builder, names);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.elasticsearch.xpack.esql.ConfigurationTestUtils.randomConfiguration;
3030
import static org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry.def;
3131
import static org.elasticsearch.xpack.esql.expression.function.FunctionResolutionStrategy.DEFAULT;
32+
import static org.hamcrest.Matchers.containsString;
3233
import static org.hamcrest.Matchers.endsWith;
3334
import static org.hamcrest.Matchers.is;
3435
import static org.mockito.Mockito.mock;
@@ -159,6 +160,9 @@ public void testConfigurationOptionalFunction() {
159160
);
160161
def = r.resolveFunction(r.resolveAlias("DUMMY"));
161162
assertEquals(ur.source(), ur.buildResolved(randomConfiguration(), def).source());
163+
164+
ParsingException e = expectThrows(ParsingException.class, () -> uf(DEFAULT).buildResolved(randomConfiguration(), def));
165+
assertThat(e.getMessage(), containsString("expects exactly one argument"));
162166
}
163167

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

0 commit comments

Comments
 (0)