jamesfredley commented on code in PR #16732:
URL: https://github.com/apache/grails-core/pull/16732#discussion_r4418430268


##########
grails-core/src/main/groovy/org/grails/config/NavigableMapConfig.java:
##########
@@ -380,20 +380,62 @@ private Object 
getValueWithDotNotatedKeySupport(NavigableMap configMap, String k
             }
             if (end > start) {
                 String segment = key.substring(start, end);
-                if (first) {
-                    value = configMap.get(segment);
-                    first = false;
-                } else if (value instanceof Map) {
-                    value = ((Map<?, ?>) value).get(segment);
-                } else {
-                    break;
+                value = childOf(first ? configMap : value, segment);
+                first = false;
+                if (value == null) {
+                    return null;
                 }
             }
             start = end + 1;
         }
         return value;
     }
 
+    /**
+     * The child a segment of a key names: the entry of a map, or the element 
of a list at a whole-number segment, as
+     * Spring Boot reads {@code server.ports.0}. A whole number with a leading 
zero, such as {@code 01}, is not an
+     * index, as in Spring Boot. A segment with an index after a name, {@code 
ports[0]}, names the element of the list
+     * under {@code ports} when the map holds no key of that name itself. 
Anything else below a value that
+     * is not a map, such as a child of a scalar, does not exist.
+     */
+    private static Object childOf(Object value, String segment) {
+        if (value instanceof Map) {
+            Map<?, ?> map = (Map<?, ?>) value;
+            if (map.containsKey(segment)) {
+                return map.get(segment);
+            }
+            int bracket = segment.indexOf('[');

Review Comment:
   With `new PropertySourcesConfig([server: [ports: [8080, 8443]]])`, 
`config.put('server.ports[1]', 9000)` then `getProperty('server.ports[1]', 
Integer)` returns 8443. The previous code returned 9000. The synthesized 
bracket lookup succeeds before the explicitly stored full key is read, so 
`put`, `putAll`, and `setAt` on that key are ignored. Read the stored full key 
before synthesizing the list element.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to