commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jarek Sacha (JIRA)" <j...@apache.org>
Subject ***UNCHECKED*** [jira] [Commented] (CONFIGURATION-714) PropertiesConfiguration builder.getConfiguration fails
Date Wed, 19 Sep 2018 12:39:00 GMT

    [ https://issues.apache.org/jira/browse/CONFIGURATION-714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16620524#comment-16620524
] 

Jarek Sacha commented on CONFIGURATION-714:
-------------------------------------------

You are correct that file did not exist. 

I needed to save a configuration created by my code (porting from Configuration v.1*). I was
confused by the title of the section in the User Guide: ["Saving"|https://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html#Saving].
I did not fully understand what is going on in the example. The example rather than just saving
a configuration, it first loads a configuration, then saves. Since my file did not exist yet
I got that exception.

You can close this issue.

Just for the record. Here is that code that worked for me when saving a new configuration
as properties:

{code:java}
// Create your configuration somewhere in the code
BaseConfiguration conf = ...

// Copy source configuration to PropertiesConfiguration
PropertiesConfiguration properties = new PropertiesConfiguration()
ConfigurationUtils.copy(conf, properties)

// Save PropertiesConfiguration
FileHandler handler = new FileHandler(properties)
handler.save(file)
{code}

> PropertiesConfiguration builder.getConfiguration fails
> ------------------------------------------------------
>
>                 Key: CONFIGURATION-714
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-714
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 2.3
>         Environment: Tested on Windows 10 with Java 10.
>            Reporter: Jarek Sacha
>            Priority: Major
>
> Call to FileBasedConfigurationBuilder.getConfiguration fails with an exception:
> {noformat}
> Could not locate: org.apache.commons.configuration2.io.FileLocator@57fd91c9[fileName=usergui.properties,basePath=<null>,sourceURL=,encoding=ISO-8859-1,fileSystem=<null>,locationStrategy=<null>]
> org.apache.commons.configuration2.ex.ConfigurationException: Could not locate: org.apache.commons.configuration2.io.FileLocator@57fd91c9[fileName=usergui.properties,basePath=<null>,sourceURL=,encoding=ISO-8859-1,fileSystem=<null>,locationStrategy=<null>]
> 	at org.apache.commons.configuration2.io.FileLocatorUtils.locateOrThrow(FileLocatorUtils.java:346)
> 	at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:972)
> 	at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:702)
> 	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initFileHandler(FileBasedConfigurationBuilder.java:312)
> 	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initResultInstance(FileBasedConfigurationBuilder.java:291)
> 	at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initResultInstance(FileBasedConfigurationBuilder.java:60)
> 	at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.createResult(BasicConfigurationBuilder.java:421)
> 	at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.getConfiguration(BasicConfigurationBuilder.java:285)
> {noformat}
> This can be reproduced with the example code from the User Guide [https://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html#Using_PropertiesConfiguration]
>  {code:java}
> Parameters params = new Parameters();
> FileBasedConfigurationBuilder<FileBasedConfiguration> builder = 
>   new FileBasedConfigurationBuilder<FileBasedConfiguration(
>     PropertiesConfiguration.class)
>       .configure(params.properties()
>         .setFileName("usergui.properties")
>         .setListDelimiterHandler(new DefaultListDelimiterHandler(',')));
> Configuration config = builder.getConfiguration();
> config.setProperty("colors.background", "#000000");
> builder.save();
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message