commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [Configuration] Bugfix for XMLConfiguration.clone()
Date Wed, 28 Feb 2007 20:57:07 GMT
Carsten,

thank you for spotting this problem! Would you be so kind to file a bug 
report in Jira [1], so we can keep track of this problem? I will have a 
look.

Thanks.
Oliver

[1] http://jakarta.apache.org/commons/configuration/issue-tracking.html

Carsten Kaiser wrote:
> Hi there,
> 
> 
> 
> the clone() operation on a XMLConfiguration does not work correctly due
> to the following problem:
> 
> 
> 
>     private class XMLFileConfigurationDelegate extends
> FileConfigurationDelegate
> 
>     {
> 
>         public void load(InputStream in) throws ConfigurationException
> 
>         {
> 
>             XMLConfiguration.this.load(in);
> 
>         }
> 
>     }
> 
> 
> 
> Obviously the delegate references the XMLConfiguration instance it is
> created in. Thus when calling
> 
> 
> 
>     public Object clone()
> 
>     {
> 
>         XMLConfiguration copy = (XMLConfiguration) super.clone();
> 
> 
> 
>         // clear document related properties
> 
>         copy.document = null;
> 
>         copy.setDelegate(createDelegate());
> 
>         // clear all references in the nodes, too
> 
>         copy.getRoot().visit(new NodeVisitor()
> 
>         {
> 
>             public void visitBeforeChildren(Node node, ConfigurationKey
> key)
> 
>             {
> 
>                 node.setReference(null);
> 
>             }
> 
>         }, null);
> 
> 
> 
>         return copy;
> 
>     }
> 
> 
> 
> the delegate still references the original XMLConfiguration, thus will
> save the content of the original one
> 
> to file instead of the clone as expected! Changing the code like this
> 
> 
> 
>         copy.setDelegate(copy.createDelegate());
> 
> 
> 
> solves the problem! Now the cloned XMLConfiguration with all its applied
> changes can be saved!
> 
> 
> 
> Regards,
> 
> CAK
> 


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


Mime
View raw message