commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [Common Configuration] Bad Exception Handling in ConfigurationFactory
Date Tue, 14 Sep 2010 19:44:01 GMT
Am 14.09.2010 16:48, schrieb Nicolás Meléndez:
> Hi there, i was looking code at ConfigurationFactory and maybe a find
> a problem, what do you think?
>
> in class ConfigurationFactory, line 184:
>
> if digester.parse(input); throws an exception,  the input stream
> doesn't close, and a process will leak of resources.
>
> i think there should be a finally which closes the stream no matter
> what happen to the parsing, maybe something like this:
>
>   try{
>              digester.parse(input);
>          }
>          catch (SAXException saxe)
>          {
>              log.error("SAX Exception caught", saxe);
>              throw new ConfigurationException("SAX Exception caught", saxe);
>          }
>   finally {
>
> 	try {
>              input.close();
> 	} catch (IOException ioe)
>          {
>              log.error("IO Exception caught", ioe);
>              throw new ConfigurationException("IO Exception caught", ioe);
>          }
>
>       }
>
>          return builder.getConfiguration();
>
>
> What people think here, i am right?
>
> Nicolas Melendez
>
This sounds reasonable and should probably be changed.

However, the ConfigurationFactory class is a bit outdated. It is fully 
replaced by DefaultConfigurationBuilder. New applications should use 
this new class. It provides a super set of the features of 
ConfigurationFactory.

Oliver

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


Mime
View raw message