gnodet-bot commented on code in PR #2354:
URL: https://github.com/apache/maven-resolver/pull/2354#discussion_r4730437106


##########
maven-resolver-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java:
##########
@@ -310,34 +314,48 @@ public static List<?> getList(RepositorySystemSession 
session, List<?> defaultVa
     }
 
     /**
-     * Gets the specified configuration property.
+     * Gets the specified configuration property. A {@link String} value is 
parsed using the syntax of
+     * {@link Properties#load(java.io.Reader)}, that is one {@code key=value} 
pair per line, with the same escaping and
+     * comment rules as a properties file. This allows clients such as Maven 
to pass map-valued properties on the
+     * command line as a string.
      *
      * @param properties the configuration properties to read, must not be 
{@code null}
      * @param defaultValue the default value to return in case none of the 
property keys is set to a map
      * @param keys the property keys to read, must not be {@code null}. The 
specified keys are read one after one until
-     *            a map is found.
+     *            a map or a string to be parsed as a map is found.
      * @return the property value or {@code null} if none
+     * @throws IllegalArgumentException if a string value cannot be parsed as 
a map, for example because of a malformed
+     *             Unicode escape
      */
     public static Map<?, ?> getMap(Map<?, ?> properties, Map<?, ?> 
defaultValue, String... keys) {
         for (String key : keys) {
             Object value = properties.get(key);
 
             if (value instanceof Map) {
                 return (Map<?, ?>) value;
+            } else if (value instanceof String) {
+                Properties parsed = new Properties();
+                try {
+                    parsed.load(new StringReader((String) value));
+                } catch (IOException | IllegalArgumentException e) {
+                    throw new IllegalArgumentException("Failed to parse map 
configuration value for " + key, e);

Review Comment:
   🐛 **[HIGH] `Properties.load()` can throw `IllegalArgumentException` — only 
`IOException` caught here**
   
   `Properties.load(Reader)` throws `IllegalArgumentException` on malformed 
Unicode escapes (`\uZZZZ`). The current catch only handles `IOException`, so a 
misconfigured map value propagates as an unexpected uncaught exception. The 
companion backport PR #2355 already has the fix.
   
   ```suggestion
                   } catch (IOException | IllegalArgumentException e) {
                       throw new IllegalArgumentException(
                               "Failed to parse map configuration value for " + 
key, e);
                   }
   ```



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