Skip to content

Detect duplicate @Name annotations in configuration properties#49638

Closed
mango766 wants to merge 1 commit intospring-projects:mainfrom
mango766:fix/duplicate-name-annotation-detection
Closed

Detect duplicate @Name annotations in configuration properties#49638
mango766 wants to merge 1 commit intospring-projects:mainfrom
mango766:fix/duplicate-name-annotation-detection

Conversation

@mango766
Copy link
Copy Markdown

This changes PropertyDescriptorResolver to throw an InvalidConfigurationMetadataException when multiple properties resolve to the same name (e.g., via duplicate @Name annotations). Previously, the processor silently dropped all but the first property, producing incomplete metadata without any warning.

The register method now uses putIfAbsent and 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

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>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 18, 2026
@snicoll
Copy link
Copy Markdown
Member

snicoll commented Mar 19, 2026

@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.

@snicoll snicoll closed this Mar 19, 2026
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Properties in '@ConfigurationProperties' annotated type shouldn't be able to define the same '@Name'

3 participants