Commons Configuration
  1. Commons Configuration
  2. CONFIGURATION-119

[configuration] ConfigurationFactory auto save overwrites properties file

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      Setting a PropertiesConfiguration autoSave=true via a ConfigurationFactory can
      cause the underlying properties file to be completely overwritten.

      Example:

      config.xml:
      <?xml version="1.0" encoding="ISO-8859-1" ?>
      <configuration>
      <properties fileName="application.properties" />
      <properties fileName="ui.properties" autoSave="true"/>
      </configuration>

      application.properties:
      application.name=Test App
      application.version = 0.01
      application.title = $

      {application.name} V${application.version}

      ui.properties:
      ui.test="stuff here"

      Execute the code:
      ConfigurationFactory factory = new ConfigurationFactory();
      URL configURL = getClass().getResource("/config.xml");
      factory.setConfigurationURL(configURL);
      try { config = factory.getConfiguration(); System.out.println(config.getString("application.title")); System.out.println(config.getString("ui.test")); config.setProperty("ui.test", "will this get saved ?"); System.out.println(config.getString("ui.test")); } catch (ConfigurationException e) { e.printStackTrace(); }

      Program output:
      12/04/2005 10:24:00
      org.apache.commons.configuration.ConfigurationFactory$FileConfigurationFactory
      createObject
      INFO: Trying to load configuration application.properties
      12/04/2005 10:24:00
      org.apache.commons.configuration.ConfigurationFactory$FileConfigurationFactory
      createObject
      INFO: Trying to load configuration ui.properties
      Test App V0.01
      "stuff here"
      will this get saved ?

      After execution
      ---------------
      application.properties:
      application.name=Test App
      application.version = 0.01
      application.title = ${application.name}

      V$

      {application.version}

      ui.properties:

      1. written by PropertiesConfiguration
      2. Tue Apr 12 10:24:00 EST 2005

      NOTE ui.test doesn't appear with either the old value or the modified one.

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Pete Cain
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development