Christian Rudolph created CONFIGURATION-646:
-----------------------------------------------

             Summary: autoSave and manual save behave differently
                 Key: CONFIGURATION-646
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-646
             Project: Commons Configuration
          Issue Type: Bug
    Affects Versions: 2.1
            Reporter: Christian Rudolph
            Priority: Minor


Using {{builder.autoSave(true)}} behaves differently than {{builder.save()}} to 
the aspect that {{builder.autoSave(true)}} doesn't write newly added properties 
to the assigned config file.

I've set up a minimal example using only two dependencies:
commons-beanutils:commons-beanutils:1.9.3 (runtime)
org.apache.commons:commons-configuration2:2.1.0 (compiletime)

{code}
public class Main {
    public static void main(String... args) {
        Parameters params = new Parameters();
        File propertiesFile = new File("conf.properties");

        FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
                new 
FileBasedConfigurationBuilder<>(PropertiesConfiguration.class)
                        .configure(params.fileBased().setFile(propertiesFile));
        builder.setAutoSave(true);
        try {
            PropertiesConfiguration config = builder.getConfiguration();
            config.setProperty("foo", "bar");
            // builder.save();
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
    }
}
{code}

This is mainly like the example from the documentation for filebased 
configurations.

{{conf.properties}} exists and is empty. With the {{builder.save}} line 
commented out, the file remains empty. Uncommenting this line results in the 
expected behavior.

I debugged a bit an saw that the property isn't added to the 
{{PropertiesConfigurationLayout}} in the first case.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to