Doc: ConfigurationClassParser's property source composition requires distinct (Resource)PropertySources names #28886
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: documentation
A documentation task
Milestone
Thanks to the team for taking the time.
Affects: 5.3.18 and main branch
Affected code
spring-framework/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
Lines 482 to 502 in 28ca0dd
Discussion
The
addPropertySource
method is affected by a bug IMO where the effect of the if statement is reverted by the fact thatPropertySource
s are hashed using theirname
property.When code reaches the affected if-statement, it means that a
PropertySource
of namefoo
is already registered in the Spring context, and that PropertySource is assigned to theexisting
variable. The idea is to replace (L499) the old property source with namefoo
with theCompositePropertySource
containing both.The problem is, given that
CompositePropertySource
holds a Set of PropertySourcesgetName()
, which is not extended currentlyIn the end, the second PropertySource won't be added and CompositePropertySource will hold only one PropertySource of name
foo
Affected case
We found a problem when multiple teams work on different Java libraries, each declaring some property sources from classpath files.
In the end, we discovered that if two libraries hold the same
env.yaml
in different packages, but the associated PropertySource name is computed by the file name (not fully qualified path), two libraries define a PropertySource namedenv.yaml
and clash.We expect this to happen even if teams define any kind of MapPropertySource with the same non-unique name. We have implemented a workaround by using the fully qualified resource URL.
Suggested solution
Have CompositePropertySource use List than Set?
Test case
Not yet available
The text was updated successfully, but these errors were encountered: