commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Bourg <sma...@lfjr.net>
Subject Re: cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestFileConfiguration.java
Date Fri, 19 Nov 2004 16:24:47 GMT
Oliver Heger wrote:
> I'm not sure, but aren't the constructors of file based configurations 
> now inconsistent with the load() method? I.e.
> 
> conf = new PropertiesConfiguration("non existing file");
> 
> won't throw an exception, but
> 
> conf = new PropertiesConfiguration();
> conf.load("non existing file");
> 
> will? Would it make sense to add constructors that take a boolean 
> createIfNecessary flag? These constructors would throw an exception 
> depending on the flag's value. The constructors without the flag would 
> always throw an exception if the file cannot be found.

I had the same thought, but I believe the semantic between the 
constructor and the load method is slightly different. When I write:

conf = new PropertiesConfiguration(new File("conf.properties"));

I intent to read *or* write to the specified file. Throwing an exception 
would shift the balance toward the "read only" scenario. On the other 
hand when I simply load with :

conf = new PropertiesConfiguration();
conf.load(new File("conf.properties"));

I only intent to read from conf.properties, and not write to it. Thus 
reporting a missing file by throwing an exception is relevant. The other 
issue is with the load() method:

conf = new PropertiesConfiguration();
conf.setFile(new File("conf.properties"));
conf.load();

Same thing here, I explicitly asked to load the file, if it's not 
possible an exception must be thrown.

Also I didn't change the String based constructor, and I'm not sure I 
want to change it yet. FileConfiguration(String) still throw an 
exception but FileConfiguration(File) doesn't. Since the String 
constructor is dedicated to locating a resource it is slightly 
different, if the resource can't be located I believe it has to be 
reported with an exception.

For example, when I write:

conf = new PropertiesConfiguration("http://foo.com/config.properties");

there is no point hidding the exception if the resource can't be 
accessed, because we don't write to non file URLs this is a read only 
scenario. It would not make sense to block the exception and write a 
config.properties file locally, this must be decided by the user.

There is also the case of the file URL :

conf = new PropertiesConfiguration("file://config.properties");

Maybe this should be handled like the File constructor.

Emmanuel Bourg

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message