Skip to content

[maven-4.0.x] ImmutableCollections.ROProperties loses Properties defaults chain #12602

Description

@elharo

ImmutableCollections.ROProperties loses Properties defaults chain

Found in: maven-4.0.x branch
File: api/maven-api-xml/src/main/java/org/apache/maven/api/xml/ImmutableCollections.java (lines ~168-176)
Severity: Medium

Description

ROProperties constructor calls super() (equivalent to Properties()) instead of preserving the parent defaults chain:

private ROProperties(Properties props) {
    super();      // calls Properties() which sets defaults=null
    if (props != null) {
        for (Map.Entry<Object, Object> e : props.entrySet()) {
            super.put(e.getKey(), e.getValue());
        }
    }
}

java.util.Properties has a defaults field that stores fallback properties. By calling super() instead of super(props != null ? props.defaults : null), the defaults chain is discarded. If props was created as new Properties(defaultsProps) where defaultsProps had key "foo"="bar", after wrapping in ROProperties, getProperty("foo") would return null instead of "bar".

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions