ConfigurationClassParser uses unified ImportStack with chained import analysis
Issue: SPR-14517
(cherry picked from commit d96a66a
)
This commit is contained in:
parent
7021a4be44
commit
ff878ea9dc
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -233,7 +233,7 @@ final class ConfigurationClass {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConfigurationClass:beanName=" + this.beanName + ",resource=" + this.resource;
|
||||
return "ConfigurationClass: beanName '" + this.beanName + "', " + this.resource;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ class ConfigurationClassParser {
|
|||
|
||||
private final List<String> propertySourceNames = new ArrayList<String>();
|
||||
|
||||
private ImportStack importStack = new ImportStack();
|
||||
private final ImportStack importStack = new ImportStack();
|
||||
|
||||
private List<DeferredImportSelectorHolder> deferredImportSelectors;
|
||||
|
||||
|
@ -182,7 +182,7 @@ class ConfigurationClassParser {
|
|||
catch (BeanDefinitionStoreException ex) {
|
||||
throw ex;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new BeanDefinitionStoreException(
|
||||
"Failed to parse configuration class [" + bd.getBeanClassName() + "]", ex);
|
||||
}
|
||||
|
@ -276,16 +276,7 @@ class ConfigurationClassParser {
|
|||
// Check the set of scanned definitions for any further config classes and parse recursively if necessary
|
||||
for (BeanDefinitionHolder holder : scannedBeanDefinitions) {
|
||||
if (ConfigurationClassUtils.checkConfigurationClassCandidate(holder.getBeanDefinition(), this.metadataReaderFactory)) {
|
||||
// Provide isolated circular import detection for scanned classes,
|
||||
// since the initial registration did not come explicitly.
|
||||
ImportStack previousStack = this.importStack;
|
||||
this.importStack = new ImportStack();
|
||||
try {
|
||||
parse(holder.getBeanDefinition().getBeanClassName(), holder.getBeanName());
|
||||
}
|
||||
finally {
|
||||
this.importStack = previousStack;
|
||||
}
|
||||
parse(holder.getBeanDefinition().getBeanClassName(), holder.getBeanName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -493,7 +484,7 @@ class ConfigurationClassParser {
|
|||
catch (BeanDefinitionStoreException ex) {
|
||||
throw ex;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new BeanDefinitionStoreException("Failed to process import candidates for configuration class [" +
|
||||
configClass.getMetadata().getClassName() + "]", ex);
|
||||
}
|
||||
|
@ -507,7 +498,7 @@ class ConfigurationClassParser {
|
|||
return;
|
||||
}
|
||||
|
||||
if (checkForCircularImports && this.importStack.contains(configClass)) {
|
||||
if (checkForCircularImports && isChainedImportOnStack(configClass)) {
|
||||
this.problemReporter.error(new CircularImportProblem(configClass, this.importStack));
|
||||
}
|
||||
else {
|
||||
|
@ -550,7 +541,7 @@ class ConfigurationClassParser {
|
|||
catch (BeanDefinitionStoreException ex) {
|
||||
throw ex;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new BeanDefinitionStoreException("Failed to process import candidates for configuration class [" +
|
||||
configClass.getMetadata().getClassName() + "]", ex);
|
||||
}
|
||||
|
@ -560,6 +551,20 @@ class ConfigurationClassParser {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isChainedImportOnStack(ConfigurationClass configClass) {
|
||||
if (this.importStack.contains(configClass)) {
|
||||
String configClassName = configClass.getMetadata().getClassName();
|
||||
AnnotationMetadata importingClass = this.importStack.getImportingClassFor(configClassName);
|
||||
while (importingClass != null) {
|
||||
if (configClassName.equals(importingClass.getClassName())) {
|
||||
return true;
|
||||
}
|
||||
importingClass = this.importStack.getImportingClassFor(importingClass.getClassName());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and
|
||||
* {@link BeanFactoryAware} contracts if implemented by the given {@code bean}.
|
||||
|
|
Loading…
Reference in New Issue