You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Fabien Nisol (JIRA)" <ji...@apache.org> on 2011/03/30 20:20:05 UTC
[jira] [Created] (CONFIGURATION-441) CompositeConfiguration does
not resolve referenced properties correctly
CompositeConfiguration does not resolve referenced properties correctly
-----------------------------------------------------------------------
Key: CONFIGURATION-441
URL: https://issues.apache.org/jira/browse/CONFIGURATION-441
Project: Commons Configuration
Issue Type: Bug
Components: Interpolation
Affects Versions: 1.5
Environment: all
Reporter: Fabien Nisol
Imagine a composite configuration consisting of
config_x : configuration one
property.one=one
property.two=two
config_y : configuration two
property.one.ref=${property.one}
When getProperty() is called on a CompositeConfiguration, property interpolation does not work if a property in config_x refers to a property in config_y, in the example, property.one.ref won't translate into "one"
This seems to be caused by the getProperty() implementation of CompositeConfiguration
{code:title=CompositeConfiguration.getProperty(String)}
/**
* Read property from underlying composite
*
* @param key key to use for mapping
*
* @return object associated with the given configuration key.
*/
public Object getProperty(String key)
{
Configuration firstMatchingConfiguration = null;
for (Iterator i = configList.iterator(); i.hasNext();)
{
Configuration config = (Configuration) i.next();
if (config.containsKey(key))
{
firstMatchingConfiguration = config;
break;
}
}
if (firstMatchingConfiguration != null)
{
return firstMatchingConfiguration.getProperty(key);
}
else
{
return null;
}
}
{code}
The methods finds the first configuration containing the key, and delegates the call to that particular configuration.
A possible fix would be to try interpolation against every configuration until an interpolation succeed.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (CONFIGURATION-441) CompositeConfiguration does
not resolve referenced properties correctly
Posted by "Fabien Nisol (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CONFIGURATION-441?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13014142#comment-13014142 ]
Fabien Nisol commented on CONFIGURATION-441:
--------------------------------------------
I think overriding the _interpolate(Object)_ and _getProperty(String key)_ on CompositeConfiguration like this should do the trick:
{code}
/**
* Read property from underlying composite
*
* @param key key to use for mapping
*
* @return object associated with the given configuration key.
*/
public Object getProperty(String key)
{
Object value = null;
for (Iterator i = configList.iterator(); i.hasNext();)
{
Configuration config = (Configuration) i.next();
if (config.containsKey(key))
{
value = config.getProperty(key);
}
}
if(value==null)
return null;
else
return interpolate(value);
}
...
/**
* Read property from underlying composite
*
* @param key key to use for mapping
*
* @return object associated with the given configuration key.
*/
public Object getProperty(String key)
{
Object value = null;
for (Iterator i = configList.iterator(); i.hasNext();)
{
Configuration config = (Configuration) i.next();
if (config.containsKey(key))
{
value = config.getProperty(key);
}
}
if(value==null)
return null;
else
return interpolate(value);
}
{code}
> CompositeConfiguration does not resolve referenced properties correctly
> -----------------------------------------------------------------------
>
> Key: CONFIGURATION-441
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-441
> Project: Commons Configuration
> Issue Type: Bug
> Components: Interpolation
> Affects Versions: 1.5
> Environment: all
> Reporter: Fabien Nisol
>
> Imagine a composite configuration consisting of
> config_x : configuration one
> property.one=one
> property.two=two
> config_y : configuration two
> property.one.ref=${property.one}
> When getProperty() is called on a CompositeConfiguration, property interpolation does not work if a property in config_x refers to a property in config_y, in the example, property.one.ref won't translate into "one"
> This seems to be caused by the getProperty() implementation of CompositeConfiguration
> {code:title=CompositeConfiguration.getProperty(String)}
> /**
> * Read property from underlying composite
> *
> * @param key key to use for mapping
> *
> * @return object associated with the given configuration key.
> */
> public Object getProperty(String key)
> {
> Configuration firstMatchingConfiguration = null;
> for (Iterator i = configList.iterator(); i.hasNext();)
> {
> Configuration config = (Configuration) i.next();
> if (config.containsKey(key))
> {
> firstMatchingConfiguration = config;
> break;
> }
> }
> if (firstMatchingConfiguration != null)
> {
> return firstMatchingConfiguration.getProperty(key);
> }
> else
> {
> return null;
> }
> }
> {code}
> The methods finds the first configuration containing the key, and delegates the call to that particular configuration.
> A possible fix would be to try interpolation against every configuration until an interpolation succeed.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Resolved] (CONFIGURATION-441) CompositeConfiguration does
not resolve referenced properties correctly
Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CONFIGURATION-441?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oliver Heger resolved CONFIGURATION-441.
----------------------------------------
Resolution: Invalid
Fix Version/s: 1.7
The problem here is that you use getProperty() which does not support variable substitution (This is documented in the Configuration interface.). If you call getString() instead, the reference will be correctly resolved.
To verify, I have added the following test case:
{code}
public void testInterpolationInMultipleConfigs()
{
Configuration c1 = new PropertiesConfiguration();
c1.addProperty("property.one", "one");
c1.addProperty("property.two", "two");
Configuration c2 = new PropertiesConfiguration();
c2.addProperty("property.one.ref", "${property.one}");
cc.addConfiguration(c1);
cc.addConfiguration(c2);
assertEquals("Wrong interpolated value", "one",
cc.getString("property.one.ref"));
}
{code}
> CompositeConfiguration does not resolve referenced properties correctly
> -----------------------------------------------------------------------
>
> Key: CONFIGURATION-441
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-441
> Project: Commons Configuration
> Issue Type: Bug
> Components: Interpolation
> Affects Versions: 1.5
> Environment: all
> Reporter: Fabien Nisol
> Fix For: 1.7
>
>
> Imagine a composite configuration consisting of
> config_x : configuration one
> property.one=one
> property.two=two
> config_y : configuration two
> property.one.ref=${property.one}
> When getProperty() is called on a CompositeConfiguration, property interpolation does not work if a property in config_x refers to a property in config_y, in the example, property.one.ref won't translate into "one"
> This seems to be caused by the getProperty() implementation of CompositeConfiguration
> {code:title=CompositeConfiguration.getProperty(String)}
> /**
> * Read property from underlying composite
> *
> * @param key key to use for mapping
> *
> * @return object associated with the given configuration key.
> */
> public Object getProperty(String key)
> {
> Configuration firstMatchingConfiguration = null;
> for (Iterator i = configList.iterator(); i.hasNext();)
> {
> Configuration config = (Configuration) i.next();
> if (config.containsKey(key))
> {
> firstMatchingConfiguration = config;
> break;
> }
> }
> if (firstMatchingConfiguration != null)
> {
> return firstMatchingConfiguration.getProperty(key);
> }
> else
> {
> return null;
> }
> }
> {code}
> The methods finds the first configuration containing the key, and delegates the call to that particular configuration.
> A possible fix would be to try interpolation against every configuration until an interpolation succeed.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira