spring-cloud / spring-cloud/spring-cloud-commons

Spring cloud bug with placeholders with comma in spring.profiles.include

Open
#1,329 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
751
Forks
744
Avg merge
1d 14h
Merged PRs (30d)
9

Description

Describe the bug
If we use placeholders with comma in spring.profiles.include (and spring.profiles.active) property like this:
spring.profiles.include=${ENVIRONMENT_PROFILE_NAME:some_profile1,some_profile2}

vanilla spring boot application works fine:
2024-01-26_190115

but spring cloud application (with consul config, for example) with spring-cloud-starter-bootstrap (bootstrap mode) can't resolve such placeholders:
2024-01-26_190209

If also set
spring.cloud.config.initialize-on-context-refresh=true
cloud application crashes on start like this:
`2024-01-26T19:28:33.299+03:00 ERROR 3808 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.cloud.consul.config.ConsulPropertySources$PropertySourceNotFoundException: java.lang.IllegalArgumentException: Illegal character in path at index 48: http://localhost:8500/v1/kv/config/application,${ENVIRONMENT_PROFILE_NAME:some_profile1/?recurse&token=
at org.springframework.cloud.consul.config.ConsulPropertySources.createPropertySource(ConsulPropertySources.java:143) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0]
at org.springframework.cloud.consul.config.ConsulPropertySourceLocator.locate(ConsulPropertySourceLocator.java:88) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0]
at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:50) ~[spring-cloud-context-4.1.0.jar:4.1.0]
at org.springframework.cloud.consul.config.ConsulPropertySourceLocator.locateCollection(ConsulPropertySourceLocator.java:71) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0]
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.doInitialize(PropertySourceBootstrapConfiguration.java:120) ~[spring-cloud-context-4.1.0.jar:4.1.0]
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:110) ~[spring-cloud-context-4.1.0.jar:4.1.0]
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:627) ~[spring-boot-3.2.2.jar:3.2.2]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:400) ~[spring-boot-3.2.2.jar:3.2.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) ~[spring-boot-3.2.2.jar:3.2.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-3.2.2.jar:3.2.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-3.2.2.jar:3.2.2]
at com.example.demo.DemoApplication.main(DemoApplication.java:10) ~[classes/:na]
Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 48: http://localhost:8500/v1/kv/config/application,${ENVIRONMENT_PROFILE_NAME:some_profile1/?recurse&token=
at java.base/java.net.URI.create(URI.java:906) ~[na:na]
at org.apache.http.client.methods.HttpGet.(HttpGet.java:66) ~[httpclient-4.5.14.jar:4.5.14]
at com.ecwid.consul.transport.AbstractHttpTransport.makeGetRequest(AbstractHttpTransport.java:33) ~[consul-api-1.4.5.jar:na]
at com.ecwid.consul.v1.ConsulRawClient.makeGetRequest(ConsulRawClient.java:139) ~[consul-api-1.4.5.jar:na]
at com.ecwid.consul.v1.ConsulRawClient.makeGetRequest(ConsulRawClient.java:128) ~[consul-api-1.4.5.jar:na]
at com.ecwid.consul.v1.kv.KeyValueConsulClient.getKVValues(KeyValueConsulClient.java:147) ~[consul-api-1.4.5.jar:na]
at com.ecwid.consul.v1.ConsulClient.getKVValues(ConsulClient.java:644) ~[consul-api-1.4.5.jar:na]
at org.springframework.cloud.consul.config.ConsulPropertySource.init(ConsulPropertySource.java:70) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0]
at org.springframework.cloud.consul.config.ConsulPropertySources.create(ConsulPropertySources.java:155) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0]
at org.springframework.cloud.consul.config.ConsulPropertySources.createPropertySource(ConsulPropertySources.java:134) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0]
... 11 common frames omitted
Caused by: java.net.URISyntaxException: Illegal character in path at index 48: http://localhost:8500/v1/kv/config/application,${ENVIRONMENT_PROFILE_NAME:some_profile1/?recurse&token=
at java.base/java.net.URI$Parser.fail(URI.java:2974) ~[na:na]
at java.base/java.net.URI$Parser.checkChars(URI.java:3145) ~[na:na]
at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3227) ~[na:na]
at java.base/java.net.URI$Parser.parse(URI.java:3175) ~[na:na]
at java.base/java.net.URI.(URI.java:623) ~[na:na]
at java.base/java.net.URI.create(URI.java:904) ~[na:na]
... 20 common frames omitted`

Also crashes when refresh Consul config by Consul KV change or by /actuator/refresh.

Spring boot 3.2.2, cloud 2023.0.0 (same as boot 2.7.18 and cloud 2021.0.9).

Look at PropertySourceBootstrapConfiguration.resolvePlaceholdersInProfiles: resolver first split by comma, then resolve placeholders.

Sample
Vanilla boot application example:
boot-app.zip

Cloud application example:
cloud-app.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java at resolvePlaceholdersInProfiles, where the issue identifies comma splitting before placeholder resolution. Reproduce the difference using the supplied boot-app.zip and cloud-app.zip, including Consul refresh behavior. Done means comma-containing default placeholders work in bootstrap and refresh scenarios without malformed Consul paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.