[
https://issues.apache.org/jira/browse/CONFIGURATION-471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13148715#comment-13148715
]
Oliver Heger commented on CONFIGURATION-471:
--------------------------------------------
This behavior is indeed inconsistent.
>From looking at the code, the result is caused by the fact that the
>inMemoryConfiguration is always stored at the end of the list of managed
>configurations. Adding of the user configuration in your second example
>actually does not have any effect because this configuration is already
>contained (as inMemoryConfiguration). So the order of the configurations is
>reverse to the desired one. This implementation detail and its consequences
>are not documented.
I assume, the original authors of CompositeConfiguration did not intend that a
single configuration could be used as both child configuration and
inMemoryConfiguration. I am not sure how to proceed. In any case, documentation
should be improved. However, changing the behavior of CompositeConfiguration in
this respect might break existing code.
Thinking about a workaround, would it be possible to use the default
inMemoryConfiguration and register an event listener at it which just copies
all changes to the user configuration? Of course, this means more effort.
> CompositeConfiguration delivers value from wrong child
> ------------------------------------------------------
>
> Key: CONFIGURATION-471
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-471
> Project: Commons Configuration
> Issue Type: Bug
> Components: File reloading
> Affects Versions: 1.7
> Reporter: Joerg Wesely
>
> I create a composite configuration with two PropertyConfigurations: a user
> configuration and a default configuration, with the userConfiguration as
> inMemoryConfiguration.
> If both configurations contain the same key, the value from
> defaultConfiguration is returned although the user configuration was added
> first. If no inMemoryConfiguration is specified, it's working ok:
> Configuration defaultConf = new PropertiesConfiguration();
> defaultConf.addProperty("prop1", "fromDefaultConfig");
>
> Configuration userConf = new PropertiesConfiguration();
> userConf.addProperty("prop1", "fromUserConfig");
>
> CompositeConfiguration noMemoryConfig = new CompositeConfiguration();
> noMemoryConfig.addConfiguration(userConf);
> noMemoryConfig.addConfiguration(defaultConf);
> System.out.println("noMemoryConfig: " + noMemoryConfig.getString("prop1"));
> // Shows "fromUserConfig"
>
> CompositeConfiguration withMemoryConfig = new
> CompositeConfiguration(userConf);
> withMemoryConfig.addConfiguration(userConf);
> withMemoryConfig.addConfiguration(defaultConf);
> System.out.println("withMemoryConfig: " +
> withMemoryConfig.getString("prop1")); // Shows "fromDefaultConfig"
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira