Skip to content

DefaultSingletonBeanRegistry::getSingleton(String beanName) attempts to create bean when it shouldn't [SPR-10674] #15302

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
spring-projects-issues opened this issue Jun 21, 2013 · 2 comments
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 21, 2013

manny veloso opened SPR-10674 and commented

According to the docs, getSingleton(String beanName) is not supposed to attempt to create the singleton if it doesn't exist.

"Only checks already instantiated singletons; does not return an Object for singleton bean definitions which have not been instantiated yet."

However, the code calls getSingleton(beanName, true). Calling getSingleton(beanName, true) attempts to create the bean if not found in the registry.

Note that a quick search through the spring sources show that the usage of getSingleton(String beanName) is consistent with the documentation ie: code that uses getSingleton(beanName) attempts to create the bean if null is returned from the function. In addition, one other use checks the existence of the bean in the registry before trying to retriev eit.


Affects: 3.1.4, 3.2.3

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jun 23, 2013

Phil Webb commented

Looks like the fix to #14452 might be the problem here:

f6209cd#commitcomment-3485152

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Note that getSingleton only allows for access to "early bean references", i.e. early access to a bean if it happens to be part of a circular reference. There is an explicit check that we're only attempting this for beans which are currently "in creation": This means that the bean kind-of exists already, its instance just hasn't been made available yet since it isn't fully constructed yet - and therefore only made available if a circular reference requires it.

In that sense, the present code is fine as-is for the intended use cases, including the getSingleton(String) variant, to the best of my understanding.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

2 participants