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

When we remove bean from the application context, its aliases must be cleared as well [SPR-16837] #21377

Open
spring-projects-issues opened this issue May 17, 2018 · 1 comment
Labels
in: core status: waiting-for-triage

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented May 17, 2018

Artem Bilan opened SPR-16837 and commented

The simple test-case to reproduce:

@Test
public void aliasesConflict() {
	GenericApplicationContext applicationContext = new GenericApplicationContext();
	applicationContext.setAllowBeanDefinitionOverriding(false);

	String beanName = "foo";
	String alias = "bar";

	applicationContext.registerBean(beanName, String.class);
	applicationContext.registerAlias(beanName, alias);

	applicationContext.removeBeanDefinition(beanName);

	applicationContext.registerBean("foo2", String.class);
	applicationContext.registerAlias("foo2", alias);

	applicationContext.close();
}

Ends up with an exception:

java.lang.IllegalStateException: Cannot register alias 'bar' for name 'foo2': It is already registered for name 'foo'.

	at org.springframework.core.SimpleAliasRegistry.registerAlias(SimpleAliasRegistry.java:60)
	at org.springframework.context.support.GenericApplicationContext.registerAlias(GenericApplicationContext.java:341)

The point is: there is no a bean for that alias any more, so why do we keep it?

Thanks


Affects: 5.0.6

Referenced from: pull request #1837

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 25, 2018

xin commented

It sames that:

When GenericApplicationContext.removeBeanDefinition(), it should remove this bean had register alias in SimpleAliasRegistry.aliasMap.

@spring-projects-issues spring-projects-issues added type: bug status: waiting-for-triage in: core and removed type: bug labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: waiting-for-triage
Projects
None yet
Development

No branches or pull requests

1 participant