From f89c026c75f26b1634883bf46304d0fe97d0a09d Mon Sep 17 00:00:00 2001 From: Gal Lalouche Date: Fri, 25 Jul 2025 12:53:35 +0300 Subject: [PATCH 1/2] ESQL: Fix NPE on empty to_lower/to_upper call --- .../xpack/esql/expression/function/EsqlFunctionRegistry.java | 4 ++-- .../esql/expression/function/EsqlFunctionRegistryTests.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java index 707de5b31ffb7..29475f7a8dce1 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java @@ -1137,10 +1137,10 @@ public static FunctionDefinition def( String... names ) { FunctionBuilder builder = (source, children, cfg) -> { - if (children.size() > 1) { + if (children.size() != 1) { throw new QlIllegalArgumentException("expects exactly one argument"); } - Expression ex = children.size() == 1 ? children.get(0) : null; + Expression ex = children.get(0); return ctorRef.build(source, ex, cfg); }; return def(function, builder, names); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistryTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistryTests.java index d8c1b40e78c48..2082db4592efb 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistryTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistryTests.java @@ -159,6 +159,9 @@ public void testConfigurationOptionalFunction() { ); def = r.resolveFunction(r.resolveAlias("DUMMY")); assertEquals(ur.source(), ur.buildResolved(randomConfiguration(), def).source()); + + ParsingException e = expectThrows(ParsingException.class, () -> uf(DEFAULT).buildResolved(randomConfiguration(), def)); + assertThat(e.getMessage(), containsString("expects exactly one argument")); } private static UnresolvedFunction uf(FunctionResolutionStrategy resolutionStrategy, Expression... children) { From f46e2ae06ce1c18550e86db36a85a8e3c2676521 Mon Sep 17 00:00:00 2001 From: Gal Lalouche Date: Fri, 25 Jul 2025 12:56:24 +0300 Subject: [PATCH 2/2] Update docs/changelog/131917.yaml --- docs/changelog/131917.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/changelog/131917.yaml diff --git a/docs/changelog/131917.yaml b/docs/changelog/131917.yaml new file mode 100644 index 0000000000000..9d69e1653e711 --- /dev/null +++ b/docs/changelog/131917.yaml @@ -0,0 +1,6 @@ +pr: 131917 +summary: Fix NPE on empty to_lower/to_upper call +area: ES|QL +type: bug +issues: + - 131913