spring-cloud / spring-cloud/spring-cloud-config
Exception when using property key with square bracket and array value
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2k
- Forks
- 1.3k
- Avg merge
- 2d 59m
- Merged PRs (30d)
- 16
Description
Describe the bug
Spring Cloud Config 2.2.5.RELEASE
I have an issue with the following configuration. The use of "[ is due to the > in the property name:
dms:
standardization:
rules:
"[XXX>yyy]":
- XXX>www
An exception is thrown:
java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.util.List (java.util.LinkedHashMap and java.util.List are in module java.base of loader 'bootstrap')
at org.springframework.cloud.config.server.environment.EnvironmentController$PropertyNavigator.setMapValue(EnvironmentController.java:375)
at org.springframework.cloud.config.server.environment.EnvironmentController$PropertyNavigator.setMapValue(EnvironmentController.java:372)
at org.springframework.cloud.config.server.environment.EnvironmentController$PropertyNavigator.setMapValue(EnvironmentController.java:372)
at org.springframework.cloud.config.server.environment.EnvironmentController$PropertyNavigator.access$100(EnvironmentController.java:349)
at org.springframework.cloud.config.server.environment.EnvironmentController.convertToMap(EnvironmentController.java:240)
at org.springframework.cloud.config.server.environment.EnvironmentController.labelledYaml(EnvironmentController.java:204)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
By debugging the code, I see that the propertyKey is converted to dms.standardization.rules[XXX>yyy][0] which results in an IllegalArgumentException because the character after a square bracket is supposed to be a digit
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java, especially convertToMap, labelledYaml, and PropertyNavigator.setMapValue near the reported line. Reproduce the YAML configuration with the square-bracket property key and array value, then trace the generated property path. Done means the configuration is converted without the ClassCastException and the property key and array value remain represented correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100