This is an automated email from the ASF dual-hosted git repository.

vlsi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new 917f60f184 [CALCITE-7853] Lambda with no parameters throws 
NullPointerException when called through FunctionExpression.getFunction()
917f60f184 is described below

commit 917f60f18410587d952a9e8320133521f36c11ee
Author: Vladimir Sitnikov <[email protected]>
AuthorDate: Wed Oct 14 11:05:30 2026 +0300

    [CALCITE-7853] Lambda with no parameters throws NullPointerException when 
called through FunctionExpression.getFunction()
    
    Calling apply() on the function that FunctionExpression.getFunction()
    returns for a lambda with no parameters threw:
    
        java.lang.NullPointerException: Cannot read the array length because 
"args" is null
            at 
org.apache.calcite.linq4j.tree.FunctionExpression.lambda$compile$0(FunctionExpression.java:88)
    
    That function is a java.lang.reflect.Proxy. For an interface method that
    takes no arguments, such as Function0.apply(), the JDK calls the proxy's
    InvocationHandler with a null argument array, and the invokable built by
    compile() reads its length. The handler now passes an empty array when
    it receives null.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../org/apache/calcite/linq4j/tree/FunctionExpression.java  |  3 ++-
 .../java/org/apache/calcite/linq4j/test/ExpressionTest.java | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git 
a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java 
b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java
index 932b904b6a..6c3670c394 100644
--- 
a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java
+++ 
b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java
@@ -104,7 +104,8 @@ public F getFunction() {
       dynamicFunction =
           (F) Proxy.newProxyInstance(classLoader,
               new Class[]{Types.toClass(type)},
-              (proxy, method, args) -> x.dynamicInvoke(args));
+              (proxy, method, args) ->
+                  x.dynamicInvoke(args == null ? new Object[0] : args));
     }
     return dynamicFunction;
   }
diff --git 
a/linq4j/src/test/java/org/apache/calcite/linq4j/test/ExpressionTest.java 
b/linq4j/src/test/java/org/apache/calcite/linq4j/test/ExpressionTest.java
index 3482e2b867..1cb24f2454 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/ExpressionTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/ExpressionTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.calcite.linq4j.test;
 
+import org.apache.calcite.linq4j.function.Function0;
 import org.apache.calcite.linq4j.function.Function1;
 import org.apache.calcite.linq4j.tree.BlockBuilder;
 import org.apache.calcite.linq4j.tree.BlockStatement;
@@ -1179,6 +1180,18 @@ public class ExpressionTest {
     assertThat(x, is(1234));
   }
 
+  /** A lambda with no parameters can be called through the function that
+   * {@link FunctionExpression#getFunction()} returns, although the JDK calls
+   * the proxy's invocation handler with a null argument array. The call used
+   * to throw NullPointerException. */
+  @Test void testLambdaWithoutParametersViaGetFunction() {
+    String x =
+        Expressions.<Function0<String>>lambda(Expressions.constant("abc"))
+            .getFunction()
+            .apply();
+    assertThat(x, is("abc"));
+  }
+
   @Test void testBlockBuilder() {
     checkBlockBuilder(
         false,

Reply via email to