Use modifiable set for @ServletComponentScan with no packages

Previously, when a project contained multiple `@ServletComponentScan`
annotated classes in classpath, and at least one annotation don't
explicitly specify `basePackages` and `basePackageClass` attribute,
the application could fail to start with an
UnsupportedOperationException. The failure occurred due to the
creating of an unmodifiable set when no base packages are configured
and a subsequent attempt to add base packages to that sit.

This commit fixes the issue by removing the use of an unmodifiable set
when `@ServletComponentScan` with no base packages in processed before
any other `@ServletComponentScan` annotations.

See gh-12715
This commit is contained in:
Wenwei Liao
2018-04-02 11:56:27 +08:00
committed by Andy Wilkinson
parent 2fd177f923
commit 7bec780281

View File

@@ -17,7 +17,6 @@
package org.springframework.boot.web.servlet;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -84,8 +83,7 @@ class ServletComponentScanRegistrar implements ImportBeanDefinitionRegistrar {
packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
}
if (packagesToScan.isEmpty()) {
return Collections
.singleton(ClassUtils.getPackageName(metadata.getClassName()));
packagesToScan.add(ClassUtils.getPackageName(metadata.getClassName()));
}
return packagesToScan;
}