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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]