commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (CONFIGURATION-646) autoSave and manual save behave differently
Date Thu, 22 Dec 2016 21:07:58 GMT

     [ https://issues.apache.org/jira/browse/CONFIGURATION-646?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Oliver Heger resolved CONFIGURATION-646.
----------------------------------------
       Resolution: Fixed
    Fix Version/s: 2.2

Your analysis was correct: the event listener for the auto-save mechanism was triggered before
the layout object, so data was saved that had not yet been updated.

The layout is normally registered as first event listener at the configuration; this is done
when the configuration is created. However, on a load operation the layout used to unregister
itself temporarily; this moved the listener registration at the end of the list.

The fix changed this behavior: The listener is not unregistered, but temporarily disabled
during a load operation.

Fixed in SVN in revision 1775740.

> 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
>             Fix For: 2.2
>
>
> 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)

Mime
View raw message