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

Detection of absolute fileNames when configuration sources are defined in a JAR file

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: 1.4
    • Component/s: None
    • Labels:
      None
    • Environment:

      Linux

      Description

      When using several configuration sources, the sources are defined in a an xml attribute like
      fileName="usergui.properties"
      The method org.apache.commons.configuration.ConfigurationUtils.getFile(String basePath, String fileName) converts the basePath and fileName into a File.
      The JavaDoc says: "The parameter strings can be relative files, absolute files and URLs as well."

      The file containing the definition of the configuration sources will become the basePath of this method.
      After a log of debugging I found, that if the basePath start with "jar:" the method assumes that the fileName is relative, evene if it's absolute. This happens, because there's a ProtocolHandler for Jar files and "jar:" is a valid protocol. So the statement "new URL(new URL(basePath), fileName)" doesn't throw a MalformedUrlException.
      Since the URL is valid, it's never checked, if the fileName may be absolute.

      Attention: this is only the case on Unix/Linux, since this is a valid URL
      jar:file:/C:/myjar.jar!/my-config.xml/someprops.properties
      while under Windows, a MalformedUrlException will be thrown, when the fileName is absolute:
      jar:file:/C:/myjar.jar!/my-config.xml/c:/someprops.properties

      I attached a patch that checks, whether the URL protocol is "jar" and the fileName is absolute. If so, the absolute file will be used.

        Attachments

        1. support-for-jar-protocol.patch.txt
          0.8 kB
          Heiko Seebach

          Activity

            People

            • Assignee:
              oheger Oliver Heger
              Reporter:
              heiko.seebach Heiko Seebach
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: