commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fabien Nisol (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CONFIGURATION-444) SubsetConfiguration does not properly handle interpolation when used on a HierarchicalConfiguration
Date Thu, 31 Mar 2011 17:42:05 GMT
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

Mime
View raw message