[
https://issues.apache.org/jira/browse/CONFIGURATION-524?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Oliver Heger resolved CONFIGURATION-524.
----------------------------------------
Resolution: Fixed
Fix Version/s: 2.0
Fixed in subversion in revision 1467449.
The {{ConfigurationInterpolator}} is now cloned, too, by all implementations of
the {{clone()}} method. The following {{clone()}} implementations had to be
adapted:
* BaseConfiguration
* BaseHierarchicalConfiguration
* CompositeConfiguration
* MapConfiguration
I hope I did not forget one.
> AbstractConfiguration does not interpolate correctly after cloning
> ------------------------------------------------------------------
>
> Key: CONFIGURATION-524
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-524
> Project: Commons Configuration
> Issue Type: Bug
> Components: Build
> Reporter: Juan Diego Gago Perez
> Assignee: Oliver Heger
> Fix For: 2.0
>
> Original Estimate: 24h
> Remaining Estimate: 24h
>
> If you clone a Configuration, does not clone the StrSubstitutor when it has
> been instanced, so the cloned copy has the same StrSubstituor than the
> original composite. If you change a property in the original compoiste it is
> changed in the cloned copy.
> Way to reproduce it :
> {code}
> public class SampleConfiguration {
> public static void main(final String[] args) {
> final String sentence = "SELECT * FORM TABLE WHERE YEAR=${year} and
> QUARTER=${quarter}";
> final CompositeConfiguration cp = new CompositeConfiguration();
> cp.addProperty("year", "2000");
> cp.addProperty("quarter", "2");
> final AbstractConfiguration clonedConfig = (AbstractConfiguration)
> ConfigurationUtils.cloneConfiguration(cp);
> cp.setProperty("year", "2001");
> clonedConfig.setProperty("year", "2002");
> System.out.println("Original sentence " +
> PropertyConverter.interpolate(sentence, cp));
> System.out.println("Cloned sentence " +
> PropertyConverter.interpolate(sentence, clonedConfig));
> final AbstractConfiguration clonedConfig2 = (AbstractConfiguration)
> ConfigurationUtils.cloneConfiguration(cp);
> cp.setProperty("year", "2003");
> clonedConfig2.setProperty("year", "2004");
> System.out.println("Original sentence " +
> PropertyConverter.interpolate(sentence, cp));
> System.out.println("Cloned (after interpolate with same
> strSubstitutor )sentence "
> + PropertyConverter.interpolate(sentence, clonedConfig2));
> }
> }
> {code}
> The solution can be to make in the following ways:
> Make the clone of the strSubstitutor in the AbstractConfigutration class.
> Create a clone method inside the StrSubtitutor and invoke it from the
> AbstractConfiguration class.
> Set null the strSubstituror when the clone method is invoked in the Abstract
> Configuration class. The next invocation to interpolate methos instances the
> strSubstitutor.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira