dylanhz created FLINK-39273:
-------------------------------
Summary: ScalarFunction throws "Argument name conflict" when eval
method contains lambda expression
Key: FLINK-39273
URL: https://issues.apache.org/jira/browse/FLINK-39273
Project: Flink
Issue Type: Bug
Components: Table SQL / Planner
Reporter: dylanhz
h3. Summary
When a {{ScalarFunction}}'s {{eval}} method body contains a lambda expression
that captures its own parameters, type inference extraction throws:
{code}
ValidationException: Argument name conflict, there are at least two argument
names that are the same.
{code}
h3. Minimal Reproduction
{code:java}
public class MyFunction extends ScalarFunction {
public String eval(Long id, String field) {
Supplier<String> supplier = () -> String.valueOf(id) + field;
return supplier.get();
}
}
{code}
h3. Root Cause
The ASM-based {{ParameterExtractor}} in {{ExtractionUtils}} extracts parameter
names from the {{LocalVariableTable}} of a class file. It matches target
methods *only by descriptor* (parameter/return types), ignoring the method name.
When a lambda inside {{eval(Long, String)}} captures both parameters {{id}} and
{{field}}, the Java compiler generates a synthetic static method
{{lambda$eval$0(Long, String) -> String}} with the *same descriptor* as the
enclosing {{eval}}.
The {{ParameterExtractor}} visits both methods, and because the lambda is
{{static}} (local variable slots start at 0) while {{eval}} is an instance
method (slot 0 = {{this}}), the lambda's variable names overwrite the eval's
entries in the {{TreeMap<Integer, String>}}, producing duplicate names
{{[field, field]}} instead of {{[id, field]}}.
h3. Fix
Add a {{methodName}} field to {{ParameterExtractor}} and match on both name
*and* descriptor in {{visitMethod}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)