Skip to content
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

Lambda proxy generation fix causes BeanNotOfRequiredTypeException #28209

Closed
oliverlockwood opened this issue Mar 21, 2022 · 5 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@oliverlockwood
Copy link

oliverlockwood commented Mar 21, 2022

I hit the problem described in #27971.

Rather than just adding the <argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine> to my Surefire configuration, I decided to upgrade to Spring-Boot 2.6.4 (from 2.6.3) to take the fix that was described (because Spring-Boot 2.6.4 uses Spring framework version 5.3.16).

However, this led me to a different error, whereby we hit a org.springframework.beans.factory.BeanNotOfRequiredTypeException for the lambda bean, specifically:

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'defaultMyThing' is expected to be of type 'com.oliverlockwood.MyThing' but was actually of type 'jdk.proxy2.$Proxy142'

At present, my not-so-pleasant options seem to come down to:

  • Run under Java 17, using --add-opens JVM argument, and get stuck on Spring Boot 2.6.3 (not great)
  • Run under Java 11 (not great), but be able to upgrade to Spring Boot 2.6.4
  • Run under Java 17 and Spring Boot 2.6.4, but change the lambda beans to be explicit (not great).

I couldn't see a ticket representing this issue, and as Spring-Boot 2.6.4's only recently been released it is plausible that I might be the first person to hit this.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 21, 2022
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Mar 21, 2022
@sbrannen
Copy link
Member

Hi @oliverlockwood,

Thanks for raising the issue. It may be a regression.

To help use analyze this, can you please provide a minimal sample application (or test class) that reproduces the BeanNotOfRequiredTypeException you are encountering (preferably as a Git repository that we can check out or a ZIP file that we can download and run)?

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Mar 21, 2022
@oliverlockwood
Copy link
Author

oliverlockwood commented Mar 24, 2022

Yes @sbrannen.

I have created repo https://github.com/oliverlockwood/spring-framework-issue-28209 which demonstrates this clearly.

It turns out that the error case requires an AOP annotation to be applied to the interface being implemented (in this case, I've used @Retryable).

Please let me know if you need any further information, but I think it should now be pretty clear.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 24, 2022
@sbrannen
Copy link
Member

Thanks for creating the repo, @oliverlockwood. Much appreciated.

We'll look into it.

@sbrannen sbrannen changed the title Lambda proxy generation fix causes instead a org.springframework.beans.factory.BeanNotOfRequiredTypeException Lambda proxy generation fix causes BeanNotOfRequiredTypeException Mar 25, 2022
@sbrannen sbrannen added this to the 5.3.18 milestone Mar 27, 2022
@sbrannen sbrannen self-assigned this Mar 27, 2022
@sbrannen sbrannen added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Mar 28, 2022
@sbrannen
Copy link
Member

sbrannen commented Mar 29, 2022

It turns out that the error case requires an AOP annotation to be applied to the interface being implemented (in this case, I've used @Retryable).

It's not because of the use of an annotation. Rather, the AOP advice for @Retryable makes use of an introduction (i.e., it introduces the org.springframework.retry.interceptor.Retryable marker interface to the proxy), and the fix for #27971 does not take this into account.

That's why the diagnostics generated by Spring Boot include the following.

The bean is of type 'jdk.proxy2.$Proxy64' and implements:
	org.springframework.retry.interceptor.Retryable
	org.springframework.aop.SpringProxy
	org.springframework.aop.framework.Advised
	org.springframework.core.DecoratingProxy

Here we see that org.springframework.retry.interceptor.Retryable is included in the set of interfaces implemented by the proxy, but the lambda interface (com.oliverlockwood.springframework.issue28209.ExampleInterface) is not.

@snicoll snicoll modified the milestones: 5.3.18, 5.3.19 Mar 31, 2022
sbrannen added a commit that referenced this issue Apr 9, 2022
This commit extracts isLambda() from AopProxyUtils and makes it
publicly available as ClassUtils.isLambdaClass().

This is a prerequisite for gh-28209.
@sbrannen
Copy link
Member

sbrannen commented Apr 9, 2022

This regression has been fixed in 6fad00e.

@oliverlockwood, I tested your example application locally with a patch containing the fix, but it would be great if you could verify the fix on your end using an upcoming 5.3.19 snapshot build and let us know that it works for your.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants