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


##########
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:
   Fixed in d633f4b057. The lookup now reads the full key as stored before it 
takes an element from the list. So after `config.put('server.ports[1]', 9000)`, 
`getProperty('server.ports[1]', Integer)` returns 9000 again, and 
`server.ports[0]` still reads 8080 from the list. The same applies to 
`server.ports.1`. The stored key is read only when the walk would otherwise 
take a list element, so other lookups are unchanged.
   
   `PropertySourcesConfigSpec` covers `put`, `putAll` and `setAt` for both 
`server.ports[1]` and `server.ports.1`, checking `getProperty` and `get`. All 
six rows returned 8443 before the fix.



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