[
https://issues.apache.org/jira/browse/CONFIGURATION-524?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Oliver Heger updated CONFIGURATION-524:
---------------------------------------
Description:
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.
was:
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 :
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));
}
}
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.
Summary: AbstractConfiguration does not interpolate correctly after
cloning (was: AbstractConfiguration does not clone correctly after
interpolation)
> 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
> 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