-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Multiple @ServletComponentScan with no base packages may cause startup to fail with an UnsupportedOperationException #12715
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description When a project contains multiple `@ServletComponentScan` annotated class in classpath, and at least one annotation don't explicitly specify `basePackages` and `basePackageClass` attribute, the application MAY fail on startup, caused by UnsupportedOperationException: <pre> java.lang.UnsupportedOperationException: null at java.util.AbstractCollection.add(AbstractCollection.java:262) at java.util.AbstractCollection.addAll(AbstractCollection.java:344) at org.springframework.boot.web.servlet.ServletComponentScanRegistrar.updatePostProcessor(ServletComponentScanRegistrar.java:62) at org.springframework.boot.web.servlet.ServletComponentScanRegistrar.registerBeanDefinitions(ServletComponentScanRegistrar.java:48) ... </pre> # Reproduction There is a single class application to reproduce this bug just for demostration. <pre> @SpringBootApplication public class SpringBootTest1 { public static void main(String[] args) { SpringApplication.run(SpringBootTest1.class, args); } @ServletComponentScan public static class Config1 { } @ServletComponentScan public static class Config2 { } } </pre>
spring-projects-issues
added
the
status: waiting-for-triage
An issue we've not yet triaged
label
Apr 2, 2018
vivimice
changed the title
#12714 UnsupportedOperationException when startup
Fix UnsupportedOperationException on startup
Apr 2, 2018
philwebb
added
for: merge-with-amendments
Needs some changes when we merge
and removed
status: waiting-for-triage
An issue we've not yet triaged
labels
Apr 2, 2018
We should ideally add a unit test for this. |
wilkinsona
changed the title
Fix UnsupportedOperationException on startup
Multiple @ServletComponentScan with no base packages may cause startup to fail with an UnsupportedOperationException
Apr 3, 2018
wilkinsona
pushed a commit
that referenced
this pull request
Apr 3, 2018
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
wilkinsona
added a commit
that referenced
this pull request
Apr 3, 2018
* gh-12715: Polish "Use modifiable set for @ServletComponentScan with no packages" Use modifiable set for @ServletComponentScan with no packages
@vivimice Thank you very much for making your first contribution to Spring Boot. This fix that you proposed is now in 1.5.x and master. I added some tests in this polishing commit. |
@wilkinsona My pleasure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#12714
Description
When a project contains multiple
@ServletComponentScan
annotated class in classpath, and at least one annotation don't explicitly specifybasePackages
andbasePackageClass
attribute, the application MAYfail on startup, caused by UnsupportedOperationException:
Reproduction
There is a single class application to reproduce this bug just for demostration.