A SpEL FunctionReference is currently limited to a static Method object, limiting what it can do drastically.

Oddly enough, the source code seems to imply that it could reference something else than a static Method, but if I'm not mistaken, there is only one code path, failing early with an exception if the method is not a static method:

https://github.com/spring-projects/spring-framework/blob/a2ef6badc4c76790128910851fdde0df55ec15f9/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java#L73-L77

then later: https://github.com/spring-projects/spring-framework/blob/a2ef6badc4c76790128910851fdde0df55ec15f9/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java#L105-L108

Anyways, it would be nice if FunctionReference could actually reference a MethodHandle, thus capturing a receiver (or even more context) that wouldn't have to leak in the signature to the "function".

Are there any show stoppers for this? AFAIU, compilation to bytecode is optional, so even that shouldn't be a problem (but maybe it is actually possible). Happy to work on a PR for this if deemed acceptable.

Comment From: fanthos

I resolved this issue by replace the original FunctionReference using my patched version, by replacing the FunctionReference AST object. I made parameters optional (default to null) in my implemention, and disable bytecode generation when object instance is not null. The patched version could call instance function.

Comment From: simonbasle

Superseded by gh-30045 Let's discuss the implementation in the PR 👍