Skip to content

Revise LambdaMessageProcessor to call well-known lambdas directly, not via reflection #3660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
artembilan opened this issue Nov 3, 2021 · 0 comments · Fixed by #3883
Closed

Comments

@artembilan
Copy link
Member

Right now it does ReflectionUtils.makeAccessible(this.method); and then Object result = this.method.invoke(this.target, args);, but probably we can call Function.apply(), GenericHandler.handle(), GenericSelector.accept(), etc. directly since we know the places LambdaMessageProcessor is used, plus we can infer the type of the lambda and delegate to respective strategy.

NOTE: With Java 17 we have to add --add-opens java.base/java.util.function=ALL-UNNAMED when Function lambda is in use.
Not having method.setAccessible(true) in this case does not help: it still fail on method.invoke() because cannot get access to the method even if it is public by definition of lambda itself.

@artembilan artembilan added this to the 6.0.x milestone Nov 3, 2021
@artembilan artembilan modified the milestones: 6.0.x, 6.0.0-M5 Sep 7, 2022
artembilan added a commit to artembilan/spring-integration that referenced this issue Sep 7, 2022
Fixes spring-projects#3660

* Change the `LambdaMessageProcessor` to invoke `Function`, `GenericHandler`,
`GenericSelector` & `GenericTransformer` explicitly without reflection.
This allows to avoid `--add-opens` for Java types to be used from reflections.
Plus this removes some overhead with native images.
And in general it is faster than reflection invocation.
garyrussell pushed a commit that referenced this issue Sep 7, 2022
Fixes #3660

* Change the `LambdaMessageProcessor` to invoke `Function`, `GenericHandler`,
`GenericSelector` & `GenericTransformer` explicitly without reflection.
This allows to avoid `--add-opens` for Java types to be used from reflections.
Plus this removes some overhead with native images.
And in general it is faster than reflection invocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant