Commons Configuration
  1. Commons Configuration
  2. CONFIGURATION-80

[configuration] ConfigurationFactory not working as expected with include path resolution

    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: All
      Platform: All

      Description

      Documentation states that ConfigurationFactory searches includes in a directory
      relative to the one including conf is located...

      Actually, some problem in various initializer methods of ConfigurationFactory
      makes it happen a way that is not natural.

      ConfigurationFactory() empty constructor sets the basePath to ".". This is okay,
      but when calling setConfigurationFileName,

      public void setConfigurationFileName(String configurationFileName)

      { File file = new File(configurationFileName).getAbsoluteFile(); this.configurationFileName = file.getName(); implicitBasePath = file.getParent(); }

      basePath is not reset to null... so a call to getBasePath will not return the
      implicitBasePath as stated.

      public String getBasePath()

      { String path = StringUtils.isEmpty(basePath) ? implicitBasePath : basePath; return StringUtils.isEmpty(path) ? "." : path; }

      using ConfigurationFactory(String configurationFileName) does not help, since it
      does not use setConfigurationFileName , so it does not set implicitBasePath

      public ConfigurationFactory(String configurationFileName)

      { this.configurationFileName = configurationFileName; }

      A work-around solution to these problems is to set the basePath to null
      explicitely after instanciation/setup...

      a possible correction is to modify the constructor and the setter like this:

      public ConfigurationFactory(String configurationFileName)

      { setConfigurationFileName(configurationFileName); }

      public void setConfigurationFileName(String configurationFileName)

      { File file = new File(configurationFileName).getAbsoluteFile(); this.configurationFileName = file.getName(); this.basePath = null; implicitBasePath = file.getParent(); }

        Activity

          People

          • Assignee:
            Unassigned
            Reporter:
            Fabien Nisol
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development