Tomas Havelka created CONFIGURATION-791:
-------------------------------------------

             Summary: ReloadingCombinedConfigurationBuilder not properly 
initialized upon definition changed
                 Key: CONFIGURATION-791
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-791
             Project: Commons Configuration
          Issue Type: Bug
    Affects Versions: 2.7
            Reporter: Tomas Havelka


I think I found an issue in {{ReloadingCombinedConfigurationBuilder}} when 
configuration definition had changed. When definition being changed, the 
builder's {{reset()}} method is called causing the builder's configuration 
parameters are resetted as well. That causes the builder cannot create the 
Configuration object, when some custom configuration has been used.

For example this code causes the problem, because when reset occurs, additional 
providers are forgotten.
{code:java}
Parameters parameters = new Parameters();
return new CustomCombinedConfigurationBuilder()
    .configure(parameters.combined()
        .setDefinitionBuilderParameters(parameters.hierarchical()
            .setFile(file)
            .setExpressionEngine(expressionEngine)
            .setListDelimiterHandler(listDelimiterHandler))
        .registerProvider("database", new DatabaseConfigurationProvider())
        .registerProvider("yaml", new YamlConfigurationProvider()));
{code}
Moreover, when the definition structure had changed, the new child builders are 
created, but the existing combined builder's {{ReloadingController}} still 
holds the original child builders but not the newly created. This causes the 
child configuration builders do not detect changes anymore. 
 This can be simply solved by resetting the reloading controller in 
{{resetParameters()}} method to force its re-creation. Following code can fix 
that:
{code:java}
public class ReloadingCombinedConfigurationBuilder extends
        CombinedConfigurationBuilder implements ReloadingControllerSupport {
    
    @Override
    public synchronized void resetParameters() {
        super.resetParameters();
        this.reloadingController = null;
    }
}
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to