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/31 19:42:05 UTC

[jira] [Created] (CONFIGURATION-444) SubsetConfiguration does not properly handle interpolation when used on a HierarchicalConfiguration

SubsetConfiguration does not properly handle interpolation when used on a HierarchicalConfiguration
---------------------------------------------------------------------------------------------------

                 Key: CONFIGURATION-444
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-444
             Project: Commons Configuration
          Issue Type: Bug
          Components: Interpolation
    Affects Versions: 1.6
         Environment: all
            Reporter: Fabien Nisol


Imaging next text files:
{code:xml}
<properties>
	<var>a_value</var>
	<prop2>
		<prop
			attr1="${var}"
			attr2="attr2"
		/>
	</prop2>
</properties>
{code}

{code:java}
...
  XMLConfiguration config2 = new XMLConfiguration("test/test2.xml");
  Configuration subset2 = config2.subset("prop2");
  Configuration subset3 = new SubsetConfiguration(subset2,"prop");
  System.err.println(subset3.getString("[@attr1]"))
...
{code}

the result is wrong:
{code}
${var}
{code}

it should be:
{code}
a_value
{code}

I think the problem is related to the _interpolate()_ method in SubsetConfiguration(), which seems to involve some kind of recursive trick that seem overcomplicated (and inefficient, since it's creating unnecessary SubsetConfiguration)..
But maybe I'm missing something.

{code}
    protected Object interpolate(Object base)
    {
        if (delimiter == null && "".equals(prefix))
        {
            return super.interpolate(base);
        }
        else
        {
            SubsetConfiguration config = new SubsetConfiguration(parent, "");
            return config.interpolate(base);
        }
    }
{code}

I think the code below would be more appropriate:

{code}
    protected Object interpolate(Object base)
    {
        if(parent instanceof AbstractConfiguration)
        {
            return ((AbstractConfiguration)parent).interpolate(base);
        } else {
            return base;
        }
    }
{code}

There's no reason to try interpolation if the parent is not implementing interpolation. 

This brings other questions about the whole interpolation thing. I really wonder why the _Configuration_ interface does not define that method, leaving or the the option to implementation to actually implement it. But that is another debate.



--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Resolved] (CONFIGURATION-444) SubsetConfiguration does not properly handle interpolation when used on a HierarchicalConfiguration

Posted by "Fabien Nisol (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-444?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Fabien Nisol resolved CONFIGURATION-444.
----------------------------------------

    Resolution: Not A Problem

The SubsetConfiguration should not be directly used as stated in comments

> SubsetConfiguration does not properly handle interpolation when used on a HierarchicalConfiguration
> ---------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-444
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-444
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Interpolation
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>
> Imaging next text files:
> {code:xml}
> <properties>
> 	<var>a_value</var>
> 	<prop2>
> 		<prop
> 			attr1="${var}"
> 			attr2="attr2"
> 		/>
> 	</prop2>
> </properties>
> {code}
> {code:java}
> ...
>   XMLConfiguration config2 = new XMLConfiguration("test/test2.xml");
>   Configuration subset2 = config2.subset("prop2");
>   Configuration subset3 = new SubsetConfiguration(subset2,"prop");
>   System.err.println(subset3.getString("[@attr1]"))
> ...
> {code}
> the result is wrong:
> {code}
> ${var}
> {code}
> it should be:
> {code}
> a_value
> {code}
> I think the problem is related to the _interpolate()_ method in SubsetConfiguration(), which seems to involve some kind of recursive trick that seem overcomplicated (and inefficient, since it's creating unnecessary SubsetConfiguration)..
> But maybe I'm missing something.
> {code}
>     protected Object interpolate(Object base)
>     {
>         if (delimiter == null && "".equals(prefix))
>         {
>             return super.interpolate(base);
>         }
>         else
>         {
>             SubsetConfiguration config = new SubsetConfiguration(parent, "");
>             return config.interpolate(base);
>         }
>     }
> {code}
> I think the code below would be more appropriate:
> {code}
>     protected Object interpolate(Object base)
>     {
>         if(parent instanceof AbstractConfiguration)
>         {
>             return ((AbstractConfiguration)parent).interpolate(base);
>         } else {
>             return base;
>         }
>     }
> {code}
> There's no reason to try interpolation if the parent is not implementing interpolation. 
> This brings other questions about the whole interpolation thing. I really wonder why the _Configuration_ interface does not define that method, leaving or the the option to implementation to actually implement it. But that is another debate.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CONFIGURATION-444) SubsetConfiguration does not properly handle interpolation when used on a HierarchicalConfiguration

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-444?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13016490#comment-13016490 ] 

Oliver Heger commented on CONFIGURATION-444:
--------------------------------------------

You should not create the {{SubsetConfiguration}} manually, but call the {{subset()}} method instead. (Please also refer to my comment on CONFIGURATION-442.) I have added a test case for {{HierarchicalConfiguration}} based on your description. The only difference is that the line
{code}
Configuration subset3 = new SubsetConfiguration(subset2,"prop");
{code}
has been replaced by
{code}
Configuration subset3 = subset2.subset("prop");
{code}

Then interpolation works as expected.

Your remarks about the implementation of {{SubsetConfiguration.interpolate()}} make sense. I don't know why it is implemented in this complicated way. In fact, the specialized configuration returned by the {{subset()}} method of {{HierarchicalConfiguration}} actually just delegates to its parent configuration for doing interpolation. When I find the time I will have a look if this implementation can be simplified.

I am not sure how the interpolation method could be exposed through the {{Configuration}} interface. It is not called directly by a client of a configuration object. Rather, the specific implementations of the various get methods are responsible for handling this feature.

> SubsetConfiguration does not properly handle interpolation when used on a HierarchicalConfiguration
> ---------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-444
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-444
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Interpolation
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>
> Imaging next text files:
> {code:xml}
> <properties>
> 	<var>a_value</var>
> 	<prop2>
> 		<prop
> 			attr1="${var}"
> 			attr2="attr2"
> 		/>
> 	</prop2>
> </properties>
> {code}
> {code:java}
> ...
>   XMLConfiguration config2 = new XMLConfiguration("test/test2.xml");
>   Configuration subset2 = config2.subset("prop2");
>   Configuration subset3 = new SubsetConfiguration(subset2,"prop");
>   System.err.println(subset3.getString("[@attr1]"))
> ...
> {code}
> the result is wrong:
> {code}
> ${var}
> {code}
> it should be:
> {code}
> a_value
> {code}
> I think the problem is related to the _interpolate()_ method in SubsetConfiguration(), which seems to involve some kind of recursive trick that seem overcomplicated (and inefficient, since it's creating unnecessary SubsetConfiguration)..
> But maybe I'm missing something.
> {code}
>     protected Object interpolate(Object base)
>     {
>         if (delimiter == null && "".equals(prefix))
>         {
>             return super.interpolate(base);
>         }
>         else
>         {
>             SubsetConfiguration config = new SubsetConfiguration(parent, "");
>             return config.interpolate(base);
>         }
>     }
> {code}
> I think the code below would be more appropriate:
> {code}
>     protected Object interpolate(Object base)
>     {
>         if(parent instanceof AbstractConfiguration)
>         {
>             return ((AbstractConfiguration)parent).interpolate(base);
>         } else {
>             return base;
>         }
>     }
> {code}
> There's no reason to try interpolation if the parent is not implementing interpolation. 
> This brings other questions about the whole interpolation thing. I really wonder why the _Configuration_ interface does not define that method, leaving or the the option to implementation to actually implement it. But that is another debate.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CONFIGURATION-444) SubsetConfiguration does not properly handle interpolation when used on a HierarchicalConfiguration

Posted by "Fabien Nisol (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-444?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13017537#comment-13017537 ] 

Fabien Nisol commented on CONFIGURATION-444:
--------------------------------------------

You cannot always control what type of Configuration is instantiated. If your base configuration happens to be a CompositeConfiguration, calling _subset()_ on it will instantiate a SubsetConfiguration. 

See my comment on bug CONFIGURATION-442 about this...

Anyway, this seem to work if I use the subset() method here, you're absolutely right. In fact, the _getKeys()_ problem of CONFIGURATION-442 was the source of our problem.

I wonder if *SubsetConfiguration* should be a "package private" class instead of a public one. It would then be obvious that this class is not intended to be used as part of the API.

I tested some code that seem to work as expected:
{code}
...
            ConfigurationFactory factory = new ConfigurationFactory("config2.xml");
            Configuration config = factory.getConfiguration();
            String prop = "[@attr1]";
            Configuration subset = config.subset("prop2.prop");
            System.err.printf("%s=%s%n",prop,subset.getString(prop));
            subset = new SubsetConfiguration(config.subset("prop2"),"prop");
            System.err.printf("%s=%s%n",prop,subset.getString(prop));...
{code}
{code:title=config2.xml}
<configuration>
	<system/>
	<xml fileName="test2.xml"/>
</configuration>
{code}

{code:title=test2.xml}
<properties>
	<var>a_value</var>
	<prop2>
		<prop
			attr1="${user.home}"
			attr2="attr2"
		/>
	</prop2>
</properties>
{code}

{code:title=output}
[@attr1]=/home/users/vr3030
[@attr1]=${user.home}
{code}




> SubsetConfiguration does not properly handle interpolation when used on a HierarchicalConfiguration
> ---------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-444
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-444
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Interpolation
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>
> Imaging next text files:
> {code:xml}
> <properties>
> 	<var>a_value</var>
> 	<prop2>
> 		<prop
> 			attr1="${var}"
> 			attr2="attr2"
> 		/>
> 	</prop2>
> </properties>
> {code}
> {code:java}
> ...
>   XMLConfiguration config2 = new XMLConfiguration("test/test2.xml");
>   Configuration subset2 = config2.subset("prop2");
>   Configuration subset3 = new SubsetConfiguration(subset2,"prop");
>   System.err.println(subset3.getString("[@attr1]"))
> ...
> {code}
> the result is wrong:
> {code}
> ${var}
> {code}
> it should be:
> {code}
> a_value
> {code}
> I think the problem is related to the _interpolate()_ method in SubsetConfiguration(), which seems to involve some kind of recursive trick that seem overcomplicated (and inefficient, since it's creating unnecessary SubsetConfiguration)..
> But maybe I'm missing something.
> {code}
>     protected Object interpolate(Object base)
>     {
>         if (delimiter == null && "".equals(prefix))
>         {
>             return super.interpolate(base);
>         }
>         else
>         {
>             SubsetConfiguration config = new SubsetConfiguration(parent, "");
>             return config.interpolate(base);
>         }
>     }
> {code}
> I think the code below would be more appropriate:
> {code}
>     protected Object interpolate(Object base)
>     {
>         if(parent instanceof AbstractConfiguration)
>         {
>             return ((AbstractConfiguration)parent).interpolate(base);
>         } else {
>             return base;
>         }
>     }
> {code}
> There's no reason to try interpolation if the parent is not implementing interpolation. 
> This brings other questions about the whole interpolation thing. I really wonder why the _Configuration_ interface does not define that method, leaving or the the option to implementation to actually implement it. But that is another debate.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira