Skip to content

Commit

Permalink
Use modifiable set for @ServletComponentScan with no packages
Browse files Browse the repository at this point in the history
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 spring-projectsgh-12715
  • Loading branch information
vivimice authored and wilkinsona committed Apr 3, 2018
1 parent 2fd177f commit 7bec780
Showing 1 changed file with 1 addition and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -84,8 +83,7 @@ private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
}
if (packagesToScan.isEmpty()) {
return Collections
.singleton(ClassUtils.getPackageName(metadata.getClassName()));
packagesToScan.add(ClassUtils.getPackageName(metadata.getClassName()));
}
return packagesToScan;
}
Expand Down

0 comments on commit 7bec780

Please sign in to comment.