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

AOT no longer generates BeanInstanceSupplier signature for a CGLIB proxy with its public type #33998

Closed
Eng-Fouad opened this issue Dec 1, 2024 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: regression A bug that is also a regression
Milestone

Comments

@Eng-Fouad
Copy link

After upgrading to Sprint Boot 3.4.0, I got this error:

> Task :compileAotTestJava FAILED
C:\Users\fouad\IdeaProjects\spring-boot-3.4-bug\build\generated\aotTestSources\io\fouad\SecurityConfig__TestContext001_BeanDefinitions.java:34: error: incompatible types: BeanInstanceSupplier<SecurityConfig$$SpringCGLIB$$0> cannot be converted to InstanceSupplier<SecurityConfig>
    InstanceSupplier<SecurityConfig> instanceSupplier = getSecurityConfigInstanceSupplier();
                                                                                         ^

Here is a reproducer: https://github.com/Eng-Fouad/spring-boot-3.4-bug

@Eng-Fouad Eng-Fouad changed the title [Since 3.4.0] error: incompatible types: BeanInstanceSupplier<SecurityConfig$$SpringCGLIB$$0> cannot be converted to InstanceSupplier<SecurityConfig> InstanceSupplier<SecurityConfig> instanceSupplier = getSecurityConfigInstanceSupplier(); [Since 3.4.0] error: incompatible types: BeanInstanceSupplier<SecurityConfig$$SpringCGLIB$$0> cannot be converted to InstanceSupplier<SecurityConfig> Dec 1, 2024
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 1, 2024
@snicoll snicoll transferred this issue from spring-projects/spring-boot Dec 2, 2024
@snicoll snicoll 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 labels Dec 2, 2024
@snicoll snicoll added this to the 6.2.1 milestone Dec 2, 2024
@snicoll snicoll added the theme: aot An issue related to Ahead-of-time processing label Dec 2, 2024
@jhoeller jhoeller added the in: core Issues in core modules (aop, beans, core, context, expression) label Dec 2, 2024
@snicoll
Copy link
Member

snicoll commented Dec 4, 2024

@Eng-Fouad thanks for the sample, I can reproduce the problem.

I suppose the actual code is more involved but mixing autowiring like that is a bit strange, especially if you target native images as you may want your config arrangement to be as lean as possible. Rather than mixing things, you could rewrite the constructor as follows:

public SecurityConfig(OAuth2AuthEntryPoint oAuth2AuthEntryPoint, @Value("${app.jwt.signature.public-key}") jwtSignaturePublicKeyBase64) {
    this.oAuth2AuthEntryPoint = oAuth2AuthEntryPoint;
    this.jwtSignaturePublicKeyBase64 = jwtSignaturePublicKeyBase64;
}

And make jwtSignaturePublicKeyBase64 final. Once you've done that, you can switch @Configuration to use proxyBeanMethods = false and it won't have to create a CGLIB proxy for it.

@Eng-Fouad
Copy link
Author

@Eng-Fouad thanks for the sample, I can reproduce the problem.

I suppose the actual code is more involved but mixing autowiring like that is a bit strange, especially if you target native images as you may want your config arrangement to be as lean as possible. Rather than mixing things, you could rewrite the constructor as follows:

public SecurityConfig(OAuth2AuthEntryPoint oAuth2AuthEntryPoint, @Value("${app.jwt.signature.public-key}") jwtSignaturePublicKeyBase64) {
    this.oAuth2AuthEntryPoint = oAuth2AuthEntryPoint;
    this.jwtSignaturePublicKeyBase64 = jwtSignaturePublicKeyBase64;
}

And make jwtSignaturePublicKeyBase64 final. Once you've done that, you can switch @Configuration to use proxyBeanMethods = false and it won't have to create a CGLIB proxy for it.

Thanks for the tips.

@snicoll
Copy link
Member

snicoll commented Dec 4, 2024

This regression has a larger scope but you're affected specifically due to the mixed nature of autowiring.

@snicoll snicoll changed the title [Since 3.4.0] error: incompatible types: BeanInstanceSupplier<SecurityConfig$$SpringCGLIB$$0> cannot be converted to InstanceSupplier<SecurityConfig> AOT no longer generates BeanInstanceSupplier signature for a CGLIB proxy with its public type Dec 5, 2024
@snicoll snicoll closed this as completed in 81a9f3d Dec 5, 2024
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) theme: aot An issue related to Ahead-of-time processing type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants