You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "goutamadwant (via GitHub)" <gi...@apache.org> on 2026/08/29 03:49:07 UTC

[PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

goutamadwant opened a new pull request, #12910:
URL: https://github.com/apache/maven/pull/12910

   Fixes #12602
   
   ## Summary
   
   `ROProperties` copied only the direct entries from the source `Properties` instance. Any values inherited through its defaults chain were therefore lost, causing `getProperty` to return `null` for inherited properties.
   
   This change snapshots the effective inherited string properties into a private defaults object before copying the direct entries. This preserves standard `Properties` behavior while:
   
   - keeping inherited properties outside the direct map
   - preserving recursive defaults
   - preserving fallback through direct non-string values
   - avoiding a mutable reference to the source defaults chain
   - avoiding an additional allocation when no inherited defaults exist
   
   The API implementation, internal XML implementation, and MDO generation template use the same behavior.
   
   ## Tests
   
   Added regression coverage for:
   
   - direct and inherited properties
   - recursive defaults
   - direct string overrides
   - direct non-string values with string defaults
   - direct-map size and membership semantics
   - isolation from later source-default mutations
   
   Verification:
   
   - `mvn clean verify`
   - `mvn -pl api/maven-api-xml -am -Dtest=ImmutableCollectionsTest -Dsurefire.failIfNoSpecifiedTests=false test`
   
   `mvn -Prun-its clean install` was also attempted. The Core IT suite did not complete locally because its extracted Maven distribution directory disappeared during execution, resulting in cascading unrelated missing-file failures. Tests executed before that point passed after the matching `4.0.x` IT support artifacts were installed.
   
   Following this checklist to help us incorporate your
   contribution quickly and easily:
   
   - [x] Your pull request should address just one issue, without pulling in other changes.
   - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line and body.
     Note that commits might be squashed by a maintainer on merge.
   - [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
     This may not always be possible but is a best-practice.
   - [x] Run `mvn verify` to make sure basic checks pass.
     A more thorough check will be performed on your pull request automatically.
   - [ ] You have run the [Core IT][core-its] successfully.
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
   - [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   [core-its]: https://maven.apache.org/core-its/core-it-suite/


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12910:
URL: https://github.com/apache/maven/pull/12910#discussion_r3886979425


##########
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;
+        }
+

Review Comment:
   ```suggestion
               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.isEmpty() ? null : 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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #12910:
URL: https://github.com/apache/maven/pull/12910#discussion_r3887200543


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

Review Comment:
   right @elharo @gnodet . The lazy initialization was intended to avoid allocating an empty `Properties` when no inherited defaults existed, but the added complexity might not be justified here. The API copy now initializes it eagerly, and I aligned the internal XML implementation and MDO template with the same behavior. Let me know thanks! 



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #12910:
URL: https://github.com/apache/maven/pull/12910#discussion_r3886444332


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

Review Comment:
   I don't follow why you don't just create defaults here. Lazy initialization is not obviously needed. What's the reasoning? Why return null when the aergument is not null?



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12910:
URL: https://github.com/apache/maven/pull/12910#discussion_r3886943404


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

Review Comment:
   +1 on @elharo's point. The lazy init avoids an allocation when the source `Properties` has no defaults chain (the common case), but it trades clarity for a marginal optimization. 
   
   A simpler version would be:
   ```java
   private static Properties copyDefaults(Properties props) {
       if (props == null) {
           return null;
       }
       Properties defaults = new Properties();
       for (String name : props.stringPropertyNames()) {
           if (!(props.get(name) instanceof String)) {
               defaults.setProperty(name, props.getProperty(name));
           }
       }
       return defaults.isEmpty() ? null : defaults;
   }
   ```
   
   Or even just always return a (possibly empty) `Properties` and drop the ternary — `super(emptyProperties)` is harmless.
   
   That said, the current code is correct as-is — just a readability nit.



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet merged PR #12910:
URL: https://github.com/apache/maven/pull/12910


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12910:
URL: https://github.com/apache/maven/pull/12910#discussion_r3887029618


##########
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;
+        }
+

Review Comment:
   Tighter suggestion — just the lazy-init and null-return:
   ```suggestion
               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;
   ```
   Removes the lazy init and always returns a `Properties` when input is non-null — addressing @elharo's point.



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #12910:
URL: https://github.com/apache/maven/pull/12910#discussion_r3887201975


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

Review Comment:
   Thanks for applying this @gnodet 



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12910:
URL: https://github.com/apache/maven/pull/12910#discussion_r3886979425


##########
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;
+        }
+

Review Comment:
   ```suggestion
               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.isEmpty() ? null : defaults;
   ```



##########
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;
           }
   ```



##########
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;
+        }
+

Review Comment:
   Tighter suggestion — just the lazy-init and null-return:
   ```suggestion
               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;
   ```
   Removes the lazy init and always returns a `Properties` when input is non-null — addressing @elharo's point.



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12910:
URL: https://github.com/apache/maven/pull/12910#discussion_r3887038335


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

Review Comment:
   Agreeing with @elharo — the lazy init adds complexity for a marginal allocation saving, and `copyDefaults(nonNullProps)` returning `null` is surprising. An empty `Properties` is a better "no defaults" sentinel — `super(emptyProperties)` is harmless.
   
   ```suggestion
               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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #12910:
URL: https://github.com/apache/maven/pull/12910#discussion_r3887200543


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

Review Comment:
   right @elharo. The lazy initialization was intended to avoid allocating an empty `Properties` when no inherited defaults existed, but the added complexity might not be justified here. The API copy now initializes it eagerly, and I aligned the internal XML implementation and MDO template with the same behavior. Let me know thanks! 



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [4.0.x] Fix #12602: Preserve Properties defaults in immutable copies [maven]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on PR #12910:
URL: https://github.com/apache/maven/pull/12910#issuecomment-5463814814

   @gnodet addressed the defaults initialization feedback across all three maintained copies. Let me know if you have any other feedack. thanks! 


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org