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

Different order of invocations for ImportAware and EmbeddedValueResolverAware with AOT-optimized contexts #28915

Closed
marcusdacoregio opened this issue Aug 2, 2022 · 6 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@marcusdacoregio
Copy link

marcusdacoregio commented Aug 2, 2022

If a configuration class implements ImportAware and EmbeddedValueResolverAware, the setEmbeddedValueResolver method is invoked first, and then setImportMetadata is second.

When the application is compiled to native or running in AOT mode, the order of the method invocation switches, causing the setImportMetadata to be invoked first.

This is causing some problems here in Spring Session

Sample
https://github.com/marcusdacoregio/embedded-value-resolver-aware-native

When running in the JVM:

2022-08-02T11:09:00.042-03:00  INFO 94512 --- [           main] com.example.MyConfig                     : Setting resolver org.springframework.beans.factory.config.EmbeddedValueResolver@7a138fc5
2022-08-02T11:09:00.043-03:00  INFO 94512 --- [           main] com.example.MyConfig                     : Setting import metadata org.springframework.beans.factory.config.EmbeddedValueResolver@7a138fc5

When running native or AOT-optimized (notice that resolver is null):

2022-08-02T11:07:41.389-03:00  INFO 94483 --- [           main] com.example.MyConfig                     : Setting import metadata null
2022-08-02T11:07:41.389-03:00  INFO 94483 --- [           main] com.example.MyConfig                     : Setting resolver org.springframework.beans.factory.config.EmbeddedValueResolver@68d0f8c8
@snicoll

This comment was marked as outdated.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 2, 2022
@snicoll snicoll changed the title Different order of invocations in Native-compiled image Different order of invocations for ImportAware and EmbeddedValueResolverAware with AOT-optimized contexts Aug 2, 2022
@snicoll
Copy link
Member

snicoll commented Aug 2, 2022

Answering to self, I can reproduce the problem with AOT on the JVM so it isn't native specific. I've updated the title accordingly.

@snicoll snicoll added type: bug A general bug theme: aot An issue related to Ahead-of-time processing and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 2, 2022
@snicoll snicoll self-assigned this Aug 2, 2022
@snicoll snicoll added this to the 6.0.0-M6 milestone Aug 2, 2022
@snicoll
Copy link
Member

snicoll commented Aug 2, 2022

OK I figured it out. Both pieces share the same callback BeanPostProcessor#postProcessBeforeInitialization. However, the import aware callback is added as a bean definition for the regular case and using .addBeanPostProcessor for the AOT case. Adding it directly means that none of the ordering applies. It should be possible to restore the regular order by adding the import aware processor as a bean.

@snicoll snicoll closed this as completed in 1fdd91e Aug 3, 2022
@snicoll
Copy link
Member

snicoll commented Aug 3, 2022

The order is restored. Thank you very much for the report and the sample @marcusdacoregio!

@snicoll
Copy link
Member

snicoll commented Aug 3, 2022

That custom code broke the native use case as it's using reflection without a hint.

@snicoll snicoll reopened this Aug 3, 2022
@snicoll
Copy link
Member

snicoll commented Aug 3, 2022

This was fixed in 3a89003

@snicoll snicoll closed this as completed Aug 3, 2022
snicoll added a commit that referenced this issue Aug 4, 2022
Contribution was not applied on the actual use case

See gh-28915
snicoll added a commit that referenced this issue Aug 4, 2022
This commit updates ImportAwareAotBeanPostProcessor to be priority
ordered, with the same order as its original BeanPostProcessor. This
makes sure that infrastructure beans can be post-processed if
necessary

See gh-28915
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants