Skip to content

CompositePropertySource doesn't fulfil EnumerablePropertySource [SPR-12788] #17385

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

Closed
spring-projects-issues opened this issue Mar 5, 2015 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 5, 2015

Konrad Garus opened SPR-12788 and commented

In #16897 CompositePropertySource became EnumerablePropertySource. It doesn't fully satisfy its contract though and it violates Liskov substitution principle.

For example, Spring Boot assumes that EnumerablePropertySource.getPropertyNames contains names of all properties available on the property source. That is not the case with CompositePropertySource containing non-enumerable property sources. See also spring-projects/spring-boot#2608


Affects: 4.1.5

Issue Links:

Referenced from: commits 7e8ffc7

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point, but I wonder what we can do about this... A CompositePropertySource won't be able to retrieve property names from a contained non-enumerable source. We cannot un-implement EnumerablePropertySource, so the only option seems to be to refine the latter's javadoc and clarify that the exposed property names are not necessarily complete. (And that separately checking for CompositePropertySource may make sense.)

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Konrad Garus commented

If you change the contract on EnumerablePropertySource, what would this class represent? A PropertySource that provides a way to see some of its property names?

If that was the official specification, it would pretty much mean: "Use at your own risk, but in the end you'll have to call getProperty to really see if it contains given property".

EnumerablePropertySource has very clean, but strong specification. I'd say if some property source cannot satisfy it, it shouldn't pretend it does. Maybe it should throw something like IllegalStateException if you call getPropertyNames and it finds itself containing a non-enumerable PropertySource?

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I like that idea: an IllegalStateException when it encounters a non-enumerable property source underneath sounds like a fine compromise.

We can easily make this change for 4.2. However, for 4.1.x, it's probably better to preserve the existing behavior, avoiding any disruption at this late maintenance stage of the branch.

Juergen

@spring-projects-issues spring-projects-issues added the type: bug A general bug label Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.2 RC1 milestone Jan 11, 2019
sbrannen added a commit that referenced this issue May 11, 2025
…aceholderConfigurer

Commit 3295289 fixed a number issues with placeholder resolution in
PropertySourcesPlaceholderConfigurer. However, in doing so, it replaced
a raw PropertySource with a CompositePropertySource which implements
EnumerablePropertySource.

Consequently, all property sources registered in the Environment must
now implement EnumerablePropertySource (which is not an actual
requirement). Otherwise, invocations of getPropertyNames() on the
CompositePropertySource result in an IllegalStateException, and that is
a breaking change which resulted in numerous build failures within the
Spring portfolio.

To address that regression, this commit introduces a private
ConfigurableEnvironmentPropertySource in
PropertySourcesPlaceholderConfigurer which is a "raw" PropertySource
that delegates directly to the PropertySources in a
ConfigurableEnvironment.

This commit also extracts the raw PropertySource for direct Environment
delegation into a new FallbackEnvironmentPropertySource.

See gh-17385
Closes gh-34861
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants