Invoke java overload methods from service task

Hi, everybody!
I’m currently working with my team with Camunda.
We’ve noticed, that Camunda doesn’t support overload java methods when invokes it from service task, for example we have a service task with expression #{someServise.someMethod(someVar)}
and in SomeService class (which is a spring bean @Service) we have two methods: someMethod(int x) and someMethod(String x).
When Camunda try to invoke method in the BeanELResolver ‘invoke’ method, it try to find this SomeService method in a loop, by name and number of params, using reflection,
so it can choose someMethod(int x) or someMethod(String x). It will choose the first method found. So we could get an exception if the method is not appropriate.
Why Camunda developers choose find method by name and number of args? At this point: Method target = findMethod(base, name, paramTypes, params.length),
in the BeanELResolver class, we have the args, so we have their types, so we can find ‘someMethod’ with String or int arg using reflection.
There is paramTypes argument in findMethod, but it’s always null, and coerceParams happens after method is found.

Hi @nightingale,

thanks for spotting this. I just gave it a try with our Spring Boot example application and can confirm that this can become an issue.

Background on this
The JUEL expression used for defining the delegate call is not able to pass on the types of the method parameters to the BeanELResolver's invoke method. Therefore, it is trying to find the first matching method in the target class. In this specific case, this might lead to the exception you mentioned.

Deriving the types from the passed-on parameters is of course something that could be used in the BeanELResolver. This is however also not trivial to do. There is varargs methods to consider, as well as that types only need to be assignable from the ones that the specific parameters bring along (e.g. a method accepting a Number parameter is fine with an Integer being passed on and such things).

But I think it is valid to open a ticket in our Issue Tracker to enhance the resolution of called methods to allow for overloaded methods as well. :+1:


1 Like