Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-788

AbstractHierarchicalFileConfiguration can lose data when #save() is interrupted by JVM abort/power failure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.10
    • None
    • File reloading
    • This occurs in any environment with any use of AbstractFileConfiguration#save(), AbstractFileConfiguration#save(URL) or AbstractFileConfiguration#save(File).

    • Patch

    Description

      When saving the current configuration, either using any of the #save() Methods or when setting a property while auto-save is enabled the method AbstractFileConfiguration#save(URL) effectively wipes the file content when opening the OutputStream.

      If the JVM gets destroyed or the machine powered down before the new configuration has been serialized to the file an empty file remains with no configuration at all.

       

      I've created a patch on top of the RELEASE_1_10_BRANCH which introduces a mitigation. The mitigation consists of a "keep backup" flag in AbstractFileConfiguration which, if set, creates a copy of the current configuration file before writing into it.

      When a configuration exception occurs upon loading the configuration again the exception will be caught and loading of the backup is attempted first before rethrowing the exception when this fails as well.

      To allow existing implementations to profit from this without touching all instances a global flag has been added to AbstractHierarchicalFileConfiguration which is then inherited by all future delegates added to any instance of AbstractHierarchicalFileConfiguration.

      Four unit tests for this mitigation feature have been added to TestHierarchicalXMLConfiguration.

      I've uploaded a repository with the commit to github: https://github.com/noamik/commons-configuration/tree/RELEASE_1_11_BRANCH

      Attachments

        Activity

          People

            Unassigned Unassigned
            cnoamik Michael Noack
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: