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

6.2.0 broke with "Could not register object [@someHash] under bean name 'blabla': there is already object [@sameHash] bound" #34427

Closed
fmarot opened this issue Feb 14, 2025 · 8 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: feedback-provided Feedback has been provided type: regression A bug that is also a regression
Milestone

Comments

@fmarot
Copy link

fmarot commented Feb 14, 2025

Hello, until 6.1.7 my program had been working fine for many years, but 6.2.0 introduced a change that made it break with:

"Could not register object [presetClientService@5404b7d9] under bean name 'blabla': there is already object [presetClientService@5404b7d9] bound"

The hash Id is the same so I'm under the impression that some bean is found in the bean registry and spring tries to re-add it in the registry. Why ?!
I was not able to create a simple reproducer yet.
To give you more details the code looks like this with 3 @configuration classes referenced:

AnnotationConfigApplicationContext sphereContext = new AnnotationConfigApplicationContext(MainSphereSpringContext.class);
AnnotationConfigApplicationContext moduleContext = new AnnotationConfigApplicationContext();
moduleContext.register(ModuleSpringConfig.class, OleaDockingSpringConfig.class);
moduleContext.setParent(sphereContext);
moduleContext.refresh();

And the failing @configuration class contains:

@Bean
public PresetClientService presetClientService() {
    return new PresetClientService(someService());
}

@Bean
public ModuleConfigPresenterImpl configPresenter() {
    return new ModuleConfigPresenterImpl(segmentActionDirectory(), presetClientService());
}

The problem comes from the call to presetClientService(). If I replace this call with null, the loading of the context is OK.
Was working fine since years and broke with 6.2.0.
I could re-try to create a real-failing sample if really needed, but for now I failed at it.
Regards

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 14, 2025
@bclozel
Copy link
Member

bclozel commented Feb 14, 2025

We are going to need that sample unfortunately. I'm not sure we have enough information to understand where the problem is.

@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue in: core Issues in core modules (aop, beans, core, context, expression) labels Feb 14, 2025
@jhoeller
Copy link
Contributor

Also, please try to reproduce this against 6.2.3 rather than 6.2.0. Several regressions have been fixed in the meantime which makes it easier to isolate where a remaining problem could be.

@fmarot
Copy link
Author

fmarot commented Feb 15, 2025

Sorry, I should have mentioned I also tested against the latest 6.2.3 and 7.0.0-M2 but they also have the same problem.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 15, 2025
@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Feb 15, 2025
@jhoeller
Copy link
Contributor

@fmarot for a start, it would help to see the stacktrace for that exception. That's essentially an assertion, for some reason addSingleton seems to be called twice for the same bean instance in your scenario.

@jhoeller jhoeller added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 17, 2025
@jhoeller jhoeller self-assigned this Feb 17, 2025
@jhoeller jhoeller added this to the 6.2.4 milestone Feb 17, 2025
@fmarot
Copy link
Author

fmarot commented Feb 17, 2025

Here is the stacktrace. I'll try to write a SSCCE (https://sscce.org/) but no guarantee.

java.lang.IllegalStateException: Could not register object [com.oleamedical.module.viewing.PresetClientServiceImpl@285489cc] under bean name 'presetClientService': there is already object [com.oleamedical.module.viewing.PresetClientServiceImpl@285489cc] bound
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.addSingleton(DefaultSingletonBeanRegistry.java:155)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:372)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.instantiateSingleton(DefaultListableBeanFactory.java:1155)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton(DefaultListableBeanFactory.java:1121)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:1056)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:987)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627)
	at com.oleamedical.module.application.AbstractSeriesViewerModuleApp.createSpringContext(AbstractSeriesViewerModuleApp.java:480)
	at com.oleamedical.module.application.AbstractSeriesViewerModuleApp.newDocumentRunnable(AbstractSeriesViewerModuleApp.java:704)

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 17, 2025
@jhoeller
Copy link
Contributor

jhoeller commented Feb 17, 2025

Interesting, that's for a top-level bean even - no nesting, no circle. Somehow we seem to end up in a pre-registered state in that regular code path, that's clearly a bug.

That helps a lot for investigating this, thanks! I'll try to sort it out for the 6.2.4 release this Thursday which we'll do just-in-time for the Spring Boot 3.4.3 release.

@fmarot
Copy link
Author

fmarot commented Feb 18, 2025

Thanks @jhoeller , I got the latest spring-beans-6.2.4-20250218.142954-8.jar and I can confirm that you fixed the problem. Big thank you !

@jhoeller
Copy link
Contributor

Thanks for the immediate testing of the snapshot, much appreciated!

pankratz76 pushed a commit to pankratz76/spring-framework that referenced this issue Feb 24, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Closes spring-projectsgh-34427

Signed-off-by: Vincent Potucek <vincent.potucek@sap.com>
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) status: feedback-provided Feedback has been provided type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants