Skip to content

[CALCITE-7853] Lambda with no parameters throws NullPointerException when called through FunctionExpression.getFunction() - #5326

Open
vlsi wants to merge 1 commit into
apache:mainfrom
vlsi:CALCITE-7853
Open

vlsi wants to merge 1 commit into
apache:mainfrom
vlsi:CALCITE-7853

Conversation

@vlsi

@vlsi vlsi commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Calling apply() on the function that FunctionExpression.getFunction() returns for a lambda with no parameters throws java.lang.NullPointerException: Cannot read the array length because "args" is null from FunctionExpression.lambda$compile$0. That function is a java.lang.reflect.Proxy, and for an interface method with no arguments, such as Function0.apply(), the JDK calls the proxy's InvocationHandler with a null argument array (InvocationHandler.invoke). The handler now passes an empty array to Invokable.dynamicInvoke when it receives null.

ExpressionTest.testLambdaWithoutParametersViaGetFunction (new) fails with that NullPointerException without the fix and passes with it.

The fix and the test come from CALCITE-7736 (#5213), which carries the same change inside the nullness migration; this PR lets it land on its own.

🤖 Generated with Claude Code

…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 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants