[ 
https://issues.apache.org/jira/browse/CONFIGURATION-429?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12935483#action_12935483
 ] 

Oliver Heger commented on CONFIGURATION-429:
--------------------------------------------

This is a little bit of a philosopic discussion. Probably you can find good 
arguments for both options: whether a key with children should be assigned an 
explicit value or not. At least XMLConfiguration is consistent with 
PropertiesConfiguration in this regard. If you have a properties file with the 
content

{code}
multicore.numberOfCores=2
singlecore=
{code}

a containsKey("multicore") would also return false.

The main problem I see with this issue is that the behavior is like that from 
the very beginning. Changing this could break existing code in an unpredictable 
way. For instance, in order to be consistent, we would then have to include all 
these keys in the iterator returned by getKeys(). So an application updating to 
a new version of Commons Configuration would suddenly see lots of unexpected 
keys.

As an alternative: Would it make sense to add a new method like 
{{containsElement()}} to HierarchicalConfiguration? The drawback is that this 
method would not be part of the generic Configuration interface.

> configuration values of nodes with children inconsistent
> --------------------------------------------------------
>
>                 Key: CONFIGURATION-429
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-429
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Silas De Munck
>   Original Estimate: 0.08h
>  Remaining Estimate: 0.08h
>
> {quote}
>       <core>
>               <multicore>
>                       <numberOfCores>2</numberOfCores>
>               </multicore>
>               <singlecore />
>       </core>
> {quote}
> In an XML configfile (see above) where I want to check if a specific node is 
> specified. I do this using the containsKey() method on the configuration.
> In this case it will return true for the key "core.singlecore" but not for 
> the key "core.multicore".
> If I change the multicore part to this (adding text as a child), it does 
> return true.
> {quote}
> <multicore>
>       ABC
>       <numberOfCores>2</numberOfCores>
> </multicore>
> {quote}
> As the containsKey() method depends on the getProperty() method, the same 
> problem exists in that method.
> In the first case:
> "core.singlecore" returns an empty string
> "core.multicore" returns null
> and in the second case, "ABC" is returned.
> I would like it to also return an empty string in the first case for 
> "core.multicore".
> This behaviour is caused by the code in lines 642-644 of 
> XMLConfiguration.java (svn):
> {quote}
>        if (text.length() > 0 || (!node.hasChildren() && node != getRoot()))
>         \{
>             node.setValue(text);
>         \}
> {quote}
> I think it can be changed to just this:
> {quote}
>         if (node != getRoot() || text.length() > 0) 
>         \{
>             node.setValue(text);
>         \}
> {quote}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to