You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stephen Colebourne <sc...@btopenworld.com> on 2004/03/17 22:30:06 UTC

[configuration] Closing opened input streams

A bug was reported against [collections] ExtendedProperties
http://issues.apache.org/bugzilla/show_bug.cgi?id=27737

I found that the input stream created in the constructor was not closed. I
just checked PropertiesConfiguration, and the load() methods seem to have
the same problem.

Stephen


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


Re: [configuration] Closing opened input streams

Posted by Emmanuel Bourg <eb...@micropole-univers.com>.
There is another stream in ClassPropertiesConfiguration if you can get a 
look Eric.

Emmanuel


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


Re: [configuration] Closing opened input streams

Posted by Emmanuel Bourg <eb...@micropole-univers.com>.
I think this patch will fix the issue for [configuration].

Emmanuel Bourg


Stephen Colebourne wrote:

> A bug was reported against [collections] ExtendedProperties
> http://issues.apache.org/bugzilla/show_bug.cgi?id=27737
> 
> I found that the input stream created in the constructor was not closed. I
> just checked PropertiesConfiguration, and the load() methods seem to have
> the same problem.
> 
> Stephen
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 

Re: [configuration] Closing opened input streams

Posted by Emmanuel Bourg <eb...@micropole-univers.com>.
Eric Pugh wrote:

> I don't know, it seems though that if we can't close the stream, should we
> keep going?

Yes I think so, the configuration is usable even if the stream cannot be 
closed. It's not a fatal error, but the user has to be notified to take 
the necessary measures. We may prefer using commons-logging here instead 
of a raw stacktrace though.

Emmanuel Bourg


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


RE: [configuration] Closing opened input streams

Posted by Eric Pugh <ep...@upstate.com>.
Okay, I am thinking of this then:

public void load(String fileName) throws ConfigurationException
    {
		InputStream is=null;
    	try {
    	    is = getPropertyStream(fileName);
    		load(is);
    	}
    	catch (IOException ioe){
    		throw new ConfigurationException("Could not load from file " +
fileName,ioe);
    	}
    	finally{
    	    if(is !=null){
    	        try{
    	            is.close();
    	        }
    	        catch (IOException ioe2){
    	            ioe2.printStackTrace();
    	        }
    	    }
    	}
    }

I don't know, it seems though that if we can't close the stream, should we
keep going?

Eric

> -----Original Message-----
> From: Emmanuel Bourg [mailto:ebourg@micropole-univers.com]
> Sent: Monday, March 29, 2004 1:48 PM
> To: Jakarta Commons Developers List
> Subject: Re: [configuration] Closing opened input streams
>
>
> Eric Pugh wrote:
>
> > We can do that..  Just need to trap and throw the resulting
> IOException as a
> > ConfigurationException then...
>
> I wouldn't throw an exception if close() fails, it doesn't prevent using
> the configuration since we have finished reading the stream at this
> point. A warning or a stack trace would be enough.
>
> Emmanuel Bourg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


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


Re: [configuration] Closing opened input streams

Posted by Emmanuel Bourg <eb...@micropole-univers.com>.
Eric Pugh wrote:

> We can do that..  Just need to trap and throw the resulting IOException as a
> ConfigurationException then...

I wouldn't throw an exception if close() fails, it doesn't prevent using 
the configuration since we have finished reading the stream at this 
point. A warning or a stack trace would be enough.

Emmanuel Bourg

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


RE: [configuration] Closing opened input streams

Posted by Eric Pugh <ep...@upstate.com>.
We can do that..  Just need to trap and throw the resulting IOException as a
ConfigurationException then...

Eric

> -----Original Message-----
> From: Emmanuel Bourg [mailto:ebourg@micropole-univers.com]
> Sent: Monday, March 29, 2004 10:34 AM
> To: Jakarta Commons Developers List
> Subject: Re: [configuration] Closing opened input streams
>
>
> I just looked at the patch :
>
> --- PropertiesConfiguration.java	28 Mar 2004 14:43:04 -0000 1.5
> +++ PropertiesConfiguration.java	28 Mar 2004 15:34:23 -0000 1.6
> @@ -99,7 +99,9 @@
>       public void load(String fileName) throws ConfigurationException
>       {
>           try {
> -            load(getPropertyStream(fileName));
> +            InputStream is = getPropertyStream(fileName);
> +            load(is);
> +            is.close();
>           }
>
>
> I think the call to the close() method should be in a finally
> block instead.
>
> Emmanuel Bourg
>
>
> Eric Pugh wrote:
> > Hi Stephen,
> >
> > I think I have just resolved the problem!  Thanks for sending it.
> >
> > Eric
> >
> >
> >>-----Original Message-----
> >>From: Stephen Colebourne [mailto:scolebourne@btopenworld.com]
> >>Sent: Wednesday, March 17, 2004 9:30 PM
> >>To: Jakarta Commons Developers List
> >>Subject: [configuration] Closing opened input streams
> >>
> >>
> >>A bug was reported against [collections] ExtendedProperties
> >>http://issues.apache.org/bugzilla/show_bug.cgi?id=27737
> >>
> >>I found that the input stream created in the constructor was
> not closed. I
> >>just checked PropertiesConfiguration, and the load() methods
> seem to have
> >>the same problem.
> >>
> >>Stephen
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


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


Re: [configuration] Closing opened input streams

Posted by Emmanuel Bourg <eb...@micropole-univers.com>.
I just looked at the patch :

--- PropertiesConfiguration.java	28 Mar 2004 14:43:04 -0000 1.5
+++ PropertiesConfiguration.java	28 Mar 2004 15:34:23 -0000 1.6
@@ -99,7 +99,9 @@
      public void load(String fileName) throws ConfigurationException
      {
          try {
-            load(getPropertyStream(fileName));
+            InputStream is = getPropertyStream(fileName);
+            load(is);
+            is.close();
          }


I think the call to the close() method should be in a finally block instead.

Emmanuel Bourg


Eric Pugh wrote:
> Hi Stephen,
> 
> I think I have just resolved the problem!  Thanks for sending it.
> 
> Eric
> 
> 
>>-----Original Message-----
>>From: Stephen Colebourne [mailto:scolebourne@btopenworld.com]
>>Sent: Wednesday, March 17, 2004 9:30 PM
>>To: Jakarta Commons Developers List
>>Subject: [configuration] Closing opened input streams
>>
>>
>>A bug was reported against [collections] ExtendedProperties
>>http://issues.apache.org/bugzilla/show_bug.cgi?id=27737
>>
>>I found that the input stream created in the constructor was not closed. I
>>just checked PropertiesConfiguration, and the load() methods seem to have
>>the same problem.
>>
>>Stephen
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 



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


RE: [configuration] Closing opened input streams

Posted by Eric Pugh <ep...@upstate.com>.
Hi Stephen,

I think I have just resolved the problem!  Thanks for sending it.

Eric

> -----Original Message-----
> From: Stephen Colebourne [mailto:scolebourne@btopenworld.com]
> Sent: Wednesday, March 17, 2004 9:30 PM
> To: Jakarta Commons Developers List
> Subject: [configuration] Closing opened input streams
>
>
> A bug was reported against [collections] ExtendedProperties
> http://issues.apache.org/bugzilla/show_bug.cgi?id=27737
>
> I found that the input stream created in the constructor was not closed. I
> just checked PropertiesConfiguration, and the load() methods seem to have
> the same problem.
>
> Stephen
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


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