Skip to content

Commit eed58ee

Browse files
committed
Improve error handling in EnableAutoConfigurationImportSelector
Previously, EnableAutoConfigurationImportSelector assumed that it would always find auto-configuration attributes from an @EnableAutoConfiguration annotation. This assumption does not hold true in certain circumstances, although exactly what those circumstances are is unclear. It could occur if the import selector were used directly, but it's package-private making that unlikey. In such circumstances a NullPointerException was being thrown. This commit asserts that the attributes are non-null and, should the assertion fail, produces an error that is more helpful than an NPE. Closes gh-1512
1 parent 468b6cb commit eed58ee

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
import org.springframework.core.io.ResourceLoader;
3232
import org.springframework.core.io.support.SpringFactoriesLoader;
3333
import org.springframework.core.type.AnnotationMetadata;
34+
import org.springframework.util.Assert;
3435

3536
/**
3637
* {@link DeferredImportSelector} to handle {@link EnableAutoConfiguration
3738
* auto-configuration}.
3839
*
3940
* @author Phillip Webb
41+
* @author Andy Wilkinson
4042
* @see EnableAutoConfiguration
4143
*/
4244
@Order(Ordered.LOWEST_PRECEDENCE)
@@ -54,6 +56,10 @@ public String[] selectImports(AnnotationMetadata metadata) {
5456
.getAnnotationAttributes(EnableAutoConfiguration.class.getName(),
5557
true));
5658

59+
Assert.notNull(attributes, "No auto-configuration attributes found. Is "
60+
+ metadata.getClassName()
61+
+ " annotated with @EnableAutoConfiguration?");
62+
5763
// Find all possible auto configuration classes, filtering duplicates
5864
List<String> factories = new ArrayList<String>(new LinkedHashSet<String>(
5965
SpringFactoriesLoader.loadFactoryNames(EnableAutoConfiguration.class,

0 commit comments

Comments
 (0)