spring-cloud / spring-cloud/spring-cloud-config

Exception when using property key with square bracket and array value

Open
#1,717 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting for votes
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

https://github.com/spring-cloud/spring-cloud-config/blob/cec480ea2dfdf819dde95479d07e186b6ecc5f7d/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java#L463

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.