Skip to content

AOT-generated CGLib proxies do not contain method overrides #34642

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

Open
dsyer opened this issue Mar 24, 2025 · 1 comment
Open

AOT-generated CGLib proxies do not contain method overrides #34642

dsyer opened this issue Mar 24, 2025 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@dsyer
Copy link
Member

dsyer commented Mar 24, 2025

My observation is that method overrides (e.g., ReplaceOverride and LookupOverride) work fine with no AOT processing, but as soon as an AOT build is carried out, the generated subclasses do not contain the indirection, so you just get the behavior from the base class for all methods (even when AOT is not enabled at runtime).

If for some reason we cannot actually transform this properly, we should throw an exception rather than silently skip the method overrides.

It's interesting to note that this is the first time I actually needed to use method overrides in 20 years of using Spring. I'd love to be able to AOT them - there doesn't seem to be a technical reason not to.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 24, 2025
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 24, 2025
@jhoeller jhoeller added this to the 6.2.x milestone Mar 24, 2025
@dsyer
Copy link
Member Author

dsyer commented Mar 25, 2025

The main part of this issue is that the method overrides are not used in AOT at runtime. I can see roughly why that happens - the bean definition instance supplier is generated using the base class, not the enhanced subclass with the overrides. It might be an ordering problem - the overrides are added in a BeanFactoryPostProcessor, which seems sensible but does obviously happen in a specific point in the lifecycle.

There is a secondary problem (with a workaround) which is that AbstractBeanDefinition.prepareMethodOverrides() is not called in the AOT build, so when the instantiating strategy is called it thinks there are no overrides on methods with arguments unless you specifically match the arguments (not necessary at runtime without AOT because prepareMethodOverrides() notices that the method name is unique). You can see this happening in logs if you set logging.level.org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy=TRACE - in the AOT build the method override is null but at runtime (if there is no AOT processing) it is non-null.

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: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants