commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CONFIGURATION-224) BaseConfiguration.getProperty() returns reference to intenal store collection object instead of a clone
Date Sat, 09 Sep 2006 19:13:23 GMT
    [ http://issues.apache.org/jira/browse/CONFIGURATION-224?page=comments#action_12433639
] 
            
Oliver Heger commented on CONFIGURATION-224:
--------------------------------------------

Good catch. This also means that the way ConfigurationDynaBean is implemented ATM it will
not properly work with other configuration types (e.g. XMLConfiguration) that do not return
modifiable list objects.

However I am not sure whether cloning a collection is the best solution. I would assume that
directly manipulating a list object returned by getProperty() is rather unusual because there
is no guarantee that this works for all configuration types. So by making use of cloning each
call to getProperty() with collections involved would become more expensive only to deal with
a special case. An alternative would be to return an unmodifiable collection (using Collections.unmodifiableCollection).
But this would have to be exactly documented because it can impact existing code. WDYT?

I would like to postpone this issue until the 1.3 release is out.

> BaseConfiguration.getProperty() returns reference to intenal store collection object
instead of a clone
> -------------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-224
>                 URL: http://issues.apache.org/jira/browse/CONFIGURATION-224
>             Project: Commons Configuration
>          Issue Type: Bug
>         Environment: 1.3RC2
>            Reporter: Gabriele Garuglieri
>            Priority: Minor
>         Attachments: list.patch
>
>
> When the property object is a List or an Array, BaseConfiguration.getProperty() returns
a reference to the object contained in the store.
> This means that changing that object, changes the content of the properties store without
an explicit setProperty() or addProperty(). 
> Also any change to the object in the store will change the object that the code has reference
to, but the user is not aware that the property has changed unless he has added a ConfigurationListener.
> Attached a patch to make the object returned by BaseConfiguration.getProperty() a clone
of store content, to avoid side effects when changing Collection properties.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message