From 7b2d375a69be2f174155e27856c331c89783ed4b Mon Sep 17 00:00:00 2001 From: Gal Lalouche Date: Fri, 25 Jul 2025 15:00:39 +0300 Subject: [PATCH] ESQL: Fix NPE on empty to_lower/to_upper call (#131917) 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. --- docs/changelog/131917.yaml | 6 ++++++ .../esql/expression/function/EsqlFunctionRegistry.java | 4 ++-- .../esql/expression/function/EsqlFunctionRegistryTests.java | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) 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 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 bf6affb49a0b2..3d05eb5291435 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 @@ -1129,10 +1129,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) {