Skip to content

@SpyBean causes BeanCurrentlyInCreationException when there are circular references #29639

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

Closed
huangyoje opened this issue Feb 3, 2022 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@huangyoje
Copy link

huangyoje commented Feb 3, 2022

When @SpyBean is used on a field which is a circular reference, will raise a BeanCurrentlyInCreationException.

Sample project that reproduces the problem: https://github.com/huangyoje/spybean-test

After some check, i think maybe SpyPostProcessor does not following the spec of SmartInstantiationAwareBeanPostProcessor.

The exposed object should be equivalent to the what postProcessBeforeInitialization / postProcessAfterInitialization would expose otherwise. Note that the object returned by this method will be used as bean reference unless the post-processor returns a different wrapper from said post-process callbacks. In other words: Those post-process callbacks may either eventually expose the same reference or alternatively return the raw bean instance from those subsequent callbacks (if the wrapper for the affected bean has been built for a call to this method already, it will be exposes as final bean reference by default).

getEarlyBeanReference, postProcessAfterInitialization may return two different spy objects in current implementation.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 3, 2022
@wilkinsona wilkinsona self-assigned this Feb 18, 2022
@wilkinsona wilkinsona added type: bug A general bug for: team-meeting An issue we'd like to discuss as a team to make progress status: waiting-for-triage An issue we've not yet triaged and removed status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Feb 18, 2022
@wilkinsona
Copy link
Member

I have a fix for this but I'd like to discuss with the team when, and even if, we want to make the change as it's not without risk.

@philwebb philwebb changed the title @SpyBean cause BeanCurrentlyInCreationException when there are circular references @SpyBean causes BeanCurrentlyInCreationException when there are circular references Feb 18, 2022
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Feb 18, 2022
@philwebb philwebb added this to the 2.5.x milestone Feb 18, 2022
wilkinsona added a commit that referenced this issue Feb 19, 2022
@snicoll snicoll modified the milestones: 2.5.x, 2.5.10 Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants