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

Fail more explicitly when AOT attempts to handle a bean definition that uses an instance supplier #29556

Closed
snicoll opened this issue Nov 23, 2022 · 3 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Nov 23, 2022

As revealed by #29555, we should throw a more tailored exception when a bean definition uses an instance supplier. If one is set, the container must honor it and there's no way for us to inspect it to generate the appropriate code.

@sdeleuze
Copy link
Contributor

While working on this, I found that the current behavior is that instance suppliers on bean definition where the bean class has a default constructor are just ignored. Boot is implicitly leveraging this behavior, see spring-projects/spring-boot#33763 for more details.

Boot and other Spring portfolio projects should probably stop using instance supplier as a first step, and then we should throw an error during AOT processing (potentially in BeanDefinitionMethodGenerator constructor).

@sdeleuze
Copy link
Contributor

sdeleuze commented Jan 11, 2023

Draft commit available at https://github.com/sdeleuze/spring-framework/tree/gh-29556.

sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Jan 19, 2023
It is by design not possible to generate code that handles
bean definitions with user-provided instance suppliers because
the JVM does not allow to get a stable reference reusable at
runtime on the lambda or method reference in the code generated
AOT.

Before this commit, such instance supplier was ignored.
After this commit, an IllegalArgumentException is thrown,
allowing projects to be aware this is not supported and enforce
related refactorings.

The related issue spring-projectsgh-29555 describes how this limitation could
be relaxed in the future.

Closes spring-projectsgh-29556
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Jan 19, 2023
It is by design not possible to generate code that handles
bean definitions with user-provided instance suppliers because
the JVM does not allow to get a stable reference reusable at
runtime on the lambda or method reference in the code generated
AOT.

Before this commit, such instance supplier was ignored.
After this commit, an IllegalArgumentException is thrown,
allowing projects to be aware this is not supported and enforce
related refactorings.

The related issue spring-projectsgh-29555 describes how this limitation could
be relaxed in the future.

Closes spring-projectsgh-29556
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Jan 19, 2023
It is by design not possible to generate code that handles
bean definitions with user-provided instance suppliers because
the JVM does not allow to get a stable reference reusable at
runtime on the lambda or method reference in the code generated
AOT.

Before this commit, such instance supplier was ignored.
After this commit, an IllegalArgumentException is thrown,
allowing projects to be aware this is not supported and enforce
related refactorings.

The related issue spring-projectsgh-29555 describes how this limitation could
be relaxed in the future.

Closes spring-projectsgh-29556
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Jan 19, 2023
It is by design not possible to generate code that handles
bean definitions with user-provided instance suppliers because
the JVM does not allow to get a stable reference reusable at
runtime on the lambda or method reference in the code generated
AOT.

Before this commit, such instance supplier was ignored.
After this commit, an IllegalArgumentException is thrown,
allowing projects to be aware this is not supported and enforce
related refactorings.

The related issue spring-projectsgh-29555 describes how this limitation could
be relaxed in the future.

Closes spring-projectsgh-29556
@jhoeller
Copy link
Contributor

Reopening for the Boot test failures reported by @wilkinsona

@jhoeller jhoeller reopened this Feb 14, 2023
mdeinum pushed a commit to mdeinum/spring-framework that referenced this issue Jun 29, 2023
It is by design not possible to generate code that handles
bean definitions with user-provided instance suppliers because
the JVM does not allow to get a stable reference reusable at
runtime on the lambda or method reference in the code generated
AOT.

Before this commit, such instance supplier was ignored.
After this commit, an IllegalArgumentException is thrown,
allowing projects to be aware this is not supported and enforce
related refactorings.

The related issue spring-projectsgh-29555 describes how this limitation could
be relaxed in the future.

Closes spring-projectsgh-29556
mdeinum pushed a commit to mdeinum/spring-framework that referenced this issue Jun 29, 2023
This commit refines the instance supplier check in
BeanDefinitionMethodGenerator constructor in order to allow
overriding by an AOT contribution.

Closes spring-projectsgh-29556
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