Detect duplicate @Name annotations in configuration properties#49638
Closed
mango766 wants to merge 1 commit intospring-projects:mainfrom
Closed
Detect duplicate @Name annotations in configuration properties#49638mango766 wants to merge 1 commit intospring-projects:mainfrom
mango766 wants to merge 1 commit intospring-projects:mainfrom
Conversation
Previously, when multiple fields in a @ConfigurationProperties class used @name annotations that resolved to the same property name, the annotation processor would silently drop all but the first property. This produced incomplete metadata without any warning to the developer. This commit changes PropertyDescriptorResolver to throw an InvalidConfigurationMetadataException when duplicate property names are detected during registration, causing a compilation error that clearly identifies the conflict. Closes spring-projects#49565 Signed-off-by: Pavel Anisimov <mango766@users.noreply.github.com>
Member
|
@mango766 thanks for the PR but the issue is still waiting for triage and we haven't made our mind yet as what we want to do. Please continue to watch the issue and resubmit if necessary. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This changes
PropertyDescriptorResolverto throw anInvalidConfigurationMetadataExceptionwhen multiple properties resolve to the same name (e.g., via duplicate@Nameannotations). Previously, the processor silently dropped all but the first property, producing incomplete metadata without any warning.The
registermethod now usesputIfAbsentand checks the return value — if a property with the same name was already registered, it raises a compilation error with a clear message identifying the conflict.Also adds a test case (
DuplicateNameAnnotationProperties) that verifies the expected compilation failure.Closes #49565
Signed-off-by: Pavel Anisimov mango766@users.noreply.github.com