Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.1
-
None
-
None
Description
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)
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(); } } }
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.