gnodet commented on code in PR #12910:
URL: https://github.com/apache/maven/pull/12910#discussion_r3886993407


##########
api/maven-api-xml/src/main/java/org/apache/maven/api/xml/ImmutableCollections.java:
##########
@@ -374,6 +374,23 @@ private ROProperties(Properties props) {
             }
         }
 
+        private static Properties copyDefaults(Properties props) {
+            if (props == null) {
+                return null;
+            }
+            Properties defaults = null;
+            for (String name : props.stringPropertyNames()) {
+                // A direct String shadows its default, while a non-String 
value does not for getProperty.
+                if (!(props.get(name) instanceof String)) {
+                    if (defaults == null) {
+                        defaults = new Properties();
+                    }
+                    defaults.setProperty(name, props.getProperty(name));
+                }
+            }
+            return defaults;
+        }
+
         @Override
         public Object put(Object key, Object value) {
             throw uoe();

Review Comment:
   Agreeing with @elharo — `copyDefaults(nonNullProps)` returning `null` is 
surprising. "No defaults to copy" is better expressed as an empty `Properties` 
than as `null`. The cost is one small object in the common case — negligible 
for a snapshot created once.
   
   ```suggestion
           private static Properties copyDefaults(Properties props) {
               if (props == null) {
                   return null;
               }
               Properties defaults = new Properties();
               for (String name : props.stringPropertyNames()) {
                   // A direct String shadows its default, while a non-String 
value does not for getProperty.
                   if (!(props.get(name) instanceof String)) {
                       defaults.setProperty(name, props.getProperty(name));
                   }
               }
               return defaults;
           }
   ```



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