commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ravi Teja (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CONFIGURATION-634) BasePath is incorrectly computed while init of CompositeConfiguration
Date Tue, 21 Jun 2016 17:46:57 GMT

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

Ravi Teja updated CONFIGURATION-634:
------------------------------------
    Description: 
The base path should be just "app" instead of {noformat}file:///C:/path/to/app{noformat} because
of which the code is trying to locate config.properties in the following path: {noformat}C:\path\to\file:\C:\path\to\app\config.properties{noformat}


In the below snippet basepath is good when handler.locate() runs but fails when running handler.load()
{code:java|title=org.apache.commons.configuration2.builder.FileLocatorUtils}
protected void initFileHandler(FileHandler handler)
            throws ConfigurationException
    {
        initEncoding(handler);
        if (handler.isLocationDefined())
        {
            handler.locate();
            handler.load();
        }
    }
{code}

If you would like to see the basepath being manipulated keep a debug point at file.isFile()
in the below snippet
{code:java|title=org.apache.commons.configuration2.io.HomeDirectoryLocationStrategy}
public URL locate(FileSystem fileSystem, FileLocator locator)
    {
        if (StringUtils.isNotEmpty(locator.getFileName()))
        {
            String basePath = fetchBasePath(locator);
            File file =
                    FileLocatorUtils.constructFile(basePath,
                            locator.getFileName());
            if (file.isFile())
            {
                return FileLocatorUtils.convertFileToURL(file);
            }
        }

        return null;
    }
{code}

Snippet failing:
{code:java}
CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(new SystemConfiguration());

final FileBasedConfigurationBuilder<FileBasedConfiguration> homeDirConfigurationBuilder
        = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
final PropertiesBuilderParameters homeDirProperties = new Parameters().properties();
final FileBasedConfigurationBuilder<FileBasedConfiguration> configurationBuilder
        = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
final PropertiesBuilderParameters properties = new Parameters().properties();

FileBasedConfigurationBuilder<FileBasedConfiguration> builder1 = homeDirConfigurationBuilder.configure(
        homeDirProperties.setLocationStrategy(new HomeDirectoryLocationStrategy(true))
                .setBasePath("app")
                .setListDelimiterHandler(new DefaultListDelimiterHandler(','))
                .setFileName("config.properties"));
FileBasedConfigurationBuilder<FileBasedConfiguration> builder2 = configurationBuilder.configure(
        properties.setLocationStrategy(new ClasspathLocationStrategy())
                .setListDelimiterHandler(new DefaultListDelimiterHandler(','))
                .setFileName("default_config.properties"));
try {
    // TODO Fails due to a bug in commons configuration FileLocatorUtils#createFullyInitializedLocatorFromURL
    config.addConfiguration(builder1.getConfiguration());
    config.addConfiguration(builder2.getConfiguration());
} catch (ConfigurationException e) {
    log.warn(configMarker, "Failed to load the properties file, loading defaults", e);
}
{code}

Stacktrace:
{noformat}
org.apache.commons.configuration2.ex.ConfigurationException: Could not locate: org.apache.commons.configuration2.io.FileLocator@353d0772[fileName=config.properties,basePath=file:///C:/path/to/app/,sourceURL=file:/C:/path/to/app/config.properties,encoding=ISO-8859-1,fileSystem=<null>,locationStrategy=org.apache.commons.configuration2.io.HomeDirectoryLocationStrategy@10e41621]
	at org.apache.commons.configuration2.io.FileLocatorUtils.locateOrThrow(FileLocatorUtils.java:346)
~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:972) ~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:702) ~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initFileHandler(FileBasedConfigurationBuilder.java:312)
~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initResultInstance(FileBasedConfigurationBuilder.java:291)
~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initResultInstance(FileBasedConfigurationBuilder.java:60)
~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.createResult(BasicConfigurationBuilder.java:421)
~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.getConfiguration(BasicConfigurationBuilder.java:285)
~[commons-configuration2-2.0.jar:2.0]
{noformat}

  was:
The base path should be just "app" instead of file:///C:/path/to/app because of which the
code is trying to locate config.properties in the following path: C:\path\to\file:\C:\path\to\app\config.properties

Snippet failing:
{code:java}
CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(new SystemConfiguration());

final FileBasedConfigurationBuilder<FileBasedConfiguration> homeDirConfigurationBuilder
        = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
final PropertiesBuilderParameters homeDirProperties = new Parameters().properties();
final FileBasedConfigurationBuilder<FileBasedConfiguration> configurationBuilder
        = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
final PropertiesBuilderParameters properties = new Parameters().properties();

FileBasedConfigurationBuilder<FileBasedConfiguration> builder1 = homeDirConfigurationBuilder.configure(
        homeDirProperties.setLocationStrategy(new HomeDirectoryLocationStrategy(true))
                .setBasePath("app")
                .setListDelimiterHandler(new DefaultListDelimiterHandler(','))
                .setFileName("config.properties"));
FileBasedConfigurationBuilder<FileBasedConfiguration> builder2 = configurationBuilder.configure(
        properties.setLocationStrategy(new ClasspathLocationStrategy())
                .setListDelimiterHandler(new DefaultListDelimiterHandler(','))
                .setFileName("default_config.properties"));
try {
    // TODO Fails due to a bug in commons configuration FileLocatorUtils#createFullyInitializedLocatorFromURL
    config.addConfiguration(builder1.getConfiguration());
    config.addConfiguration(builder2.getConfiguration());
} catch (ConfigurationException e) {
    log.warn(configMarker, "Failed to load the properties file, loading defaults", e);
}
{code}

Stacktrace:
{noformat}
org.apache.commons.configuration2.ex.ConfigurationException: Could not locate: org.apache.commons.configuration2.io.FileLocator@353d0772[fileName=config.properties,basePath=file:///C:/path/to/app/,sourceURL=file:/C:/path/to/app/config.properties,encoding=ISO-8859-1,fileSystem=<null>,locationStrategy=org.apache.commons.configuration2.io.HomeDirectoryLocationStrategy@10e41621]
	at org.apache.commons.configuration2.io.FileLocatorUtils.locateOrThrow(FileLocatorUtils.java:346)
~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:972) ~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:702) ~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initFileHandler(FileBasedConfigurationBuilder.java:312)
~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initResultInstance(FileBasedConfigurationBuilder.java:291)
~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initResultInstance(FileBasedConfigurationBuilder.java:60)
~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.createResult(BasicConfigurationBuilder.java:421)
~[commons-configuration2-2.0.jar:2.0]
	at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.getConfiguration(BasicConfigurationBuilder.java:285)
~[commons-configuration2-2.0.jar:2.0]
{noformat}


> BasePath is incorrectly computed while init of CompositeConfiguration
> ---------------------------------------------------------------------
>
>                 Key: CONFIGURATION-634
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-634
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Windows Server 2008 R2
> Oracle JDK 1.8.0_92
>            Reporter: Ravi Teja
>            Priority: Blocker
>
> The base path should be just "app" instead of {noformat}file:///C:/path/to/app{noformat}
because of which the code is trying to locate config.properties in the following path: {noformat}C:\path\to\file:\C:\path\to\app\config.properties{noformat}
> In the below snippet basepath is good when handler.locate() runs but fails when running
handler.load()
> {code:java|title=org.apache.commons.configuration2.builder.FileLocatorUtils}
> protected void initFileHandler(FileHandler handler)
>             throws ConfigurationException
>     {
>         initEncoding(handler);
>         if (handler.isLocationDefined())
>         {
>             handler.locate();
>             handler.load();
>         }
>     }
> {code}
> If you would like to see the basepath being manipulated keep a debug point at file.isFile()
in the below snippet
> {code:java|title=org.apache.commons.configuration2.io.HomeDirectoryLocationStrategy}
> public URL locate(FileSystem fileSystem, FileLocator locator)
>     {
>         if (StringUtils.isNotEmpty(locator.getFileName()))
>         {
>             String basePath = fetchBasePath(locator);
>             File file =
>                     FileLocatorUtils.constructFile(basePath,
>                             locator.getFileName());
>             if (file.isFile())
>             {
>                 return FileLocatorUtils.convertFileToURL(file);
>             }
>         }
>         return null;
>     }
> {code}
> Snippet failing:
> {code:java}
> CompositeConfiguration config = new CompositeConfiguration();
> config.addConfiguration(new SystemConfiguration());
> final FileBasedConfigurationBuilder<FileBasedConfiguration> homeDirConfigurationBuilder
>         = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
> final PropertiesBuilderParameters homeDirProperties = new Parameters().properties();
> final FileBasedConfigurationBuilder<FileBasedConfiguration> configurationBuilder
>         = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
> final PropertiesBuilderParameters properties = new Parameters().properties();
> FileBasedConfigurationBuilder<FileBasedConfiguration> builder1 = homeDirConfigurationBuilder.configure(
>         homeDirProperties.setLocationStrategy(new HomeDirectoryLocationStrategy(true))
>                 .setBasePath("app")
>                 .setListDelimiterHandler(new DefaultListDelimiterHandler(','))
>                 .setFileName("config.properties"));
> FileBasedConfigurationBuilder<FileBasedConfiguration> builder2 = configurationBuilder.configure(
>         properties.setLocationStrategy(new ClasspathLocationStrategy())
>                 .setListDelimiterHandler(new DefaultListDelimiterHandler(','))
>                 .setFileName("default_config.properties"));
> try {
>     // TODO Fails due to a bug in commons configuration FileLocatorUtils#createFullyInitializedLocatorFromURL
>     config.addConfiguration(builder1.getConfiguration());
>     config.addConfiguration(builder2.getConfiguration());
> } catch (ConfigurationException e) {
>     log.warn(configMarker, "Failed to load the properties file, loading defaults", e);
> }
> {code}
> Stacktrace:
> {noformat}
> org.apache.commons.configuration2.ex.ConfigurationException: Could not locate: org.apache.commons.configuration2.io.FileLocator@353d0772[fileName=config.properties,basePath=file:///C:/path/to/app/,sourceURL=file:/C:/path/to/app/config.properties,encoding=ISO-8859-1,fileSystem=<null>,locationStrategy=org.apache.commons.configuration2.io.HomeDirectoryLocationStrategy@10e41621]
> 	at org.apache.commons.configuration2.io.FileLocatorUtils.locateOrThrow(FileLocatorUtils.java:346)
~[commons-configuration2-2.0.jar:2.0]
> 	at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:972) ~[commons-configuration2-2.0.jar:2.0]
> 	at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:702) ~[commons-configuration2-2.0.jar:2.0]
> 	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initFileHandler(FileBasedConfigurationBuilder.java:312)
~[commons-configuration2-2.0.jar:2.0]
> 	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initResultInstance(FileBasedConfigurationBuilder.java:291)
~[commons-configuration2-2.0.jar:2.0]
> 	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initResultInstance(FileBasedConfigurationBuilder.java:60)
~[commons-configuration2-2.0.jar:2.0]
> 	at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.createResult(BasicConfigurationBuilder.java:421)
~[commons-configuration2-2.0.jar:2.0]
> 	at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.getConfiguration(BasicConfigurationBuilder.java:285)
~[commons-configuration2-2.0.jar:2.0]
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message