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

SimpleAliasRegistry.canonicalName can produce an endless loop [SPR-7274] #11933

Closed
spring-projects-issues opened this issue Jun 10, 2010 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Joern Huxhorn opened SPR-7274 and commented

The corresponding stacktrace looks like this:

"main" prio=5 tid=102800800 nid=0x100501000 runnable [1004ff000]
java.lang.Thread.State: RUNNABLE
at org.springframework.core.SimpleAliasRegistry.canonicalName(SimpleAliasRegistry.java:156)
at org.springframework.beans.factory.support.AbstractBeanFactory.transformedBeanName(AbstractBeanFactory.java:966)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1317)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

  • locked <107d35848> (a java.util.concurrent.ConcurrentHashMap)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
  • locked <107d35a40> (a java.util.concurrent.ConcurrentHashMap)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
  • locked <107d06848> (a java.lang.Object)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)

The endless loop is in line 156:
/**

  • Determine the raw name, resolving aliases to canonical names.
  • @param name the user-specified name
  • @return the transformed name
    */
    public String canonicalName(String name) {
    String canonicalName = name;
    // Handle aliasing.
    String resolvedName = null;
    do {
    resolvedName = this.aliasMap.get(canonicalName);
    if (resolvedName != null) {
    canonicalName = resolvedName;
    }
    }
    while (resolvedName != null); // <= here
    return canonicalName;
    }

I have this hang in a quite complex config file and I guess that there is some kind of alias loop. This, however, shouldn't result in an endless loop but in some useful error message containing the "loop path" of the aliases.


Affects: 3.0.2

Referenced from: commits 11330ba

@spring-projects-issues
Copy link
Collaborator Author

Joern Huxhorn commented

Suggested fix (untested, I didn't even compile;)):
{{ public String canonicalName(String name) {
String canonicalName = name;
List<String> loopCheck=new ArrayList<String>();
loopCheck.add(name);
// Handle aliasing.
for(;;) {
String resolvedName = this.aliasMap.get(canonicalName);
if (resolvedName != null) {
if(loopCheck.contains(resolvedName)) {
throw new IllegalStateException("Alias '"+name+"' is part of a loop ("+loopCheck+")!");
}
loopCheck.add(resolvedName);

			canonicalName = resolvedName;
		} else {
			break;
		}
	}
	return canonicalName;
}

}}

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good catch! Fixed for 3.0.3, in registerAlias so that it is being detected early and avoids runtime overhead in canonicalName itself. This will be available in tonight's 3.0.3 snapshot - feel free to give it an early try...

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.3 milestone Jan 11, 2019
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) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants