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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Index: src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java,v
retrieving revision 1.5
diff -u -r1.5 BasePropertiesConfiguration.java
--- src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java  13 Mar 
2004 17:34:37 -0000      1.5
+++ src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java  22 Mar 
2004 17:58:49 -0000
@@ -137,7 +137,7 @@
      * Load the properties from the given input stream.
      *
      * @param input An InputStream.
-     * @throws IOException
+     * @throws ConfigurationException
      */
     public void load(InputStream input)
         throws ConfigurationException
@@ -151,7 +151,7 @@
      *
      * @param input An InputStream.
      * @param enc An encoding.
-     * @exception IOException
+     * @exception ConfigurationException
      */
     public synchronized void load(InputStream input, String enc)
         throws ConfigurationException
@@ -203,7 +203,18 @@
                         String [] files = StringUtils.split(value, ",");
                         for (int cnt = 0 ; cnt < files.length ; cnt++)
                         {
-                            load(getPropertyStream(files[cnt].trim()));
+                            InputStream in = null;
+
+                            try {
+                                in = getPropertyStream(files[cnt].trim());
+                                load(in);
+                            } finally {
+                                try {
+                                    if (in != null) {
+                                        in.close();
+                                    }
+                                } catch (IOException e) {}
+                            }
                         }
                     }
                 }
@@ -224,7 +235,7 @@
      * properties with multiple values are saved comma seperated.
      *
      * @param filename name of the properties file
-     * @throws IOException
+     * @throws ConfigurationException
      */
     public void save(String filename)
         throws ConfigurationException
Index: src/java/org/apache/commons/configuration/ClassPropertiesConfiguration.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ClassPropertiesConfiguration.java,v
retrieving revision 1.5
diff -u -r1.5 ClassPropertiesConfiguration.java
--- src/java/org/apache/commons/configuration/ClassPropertiesConfiguration.java 13 Mar 
2004 17:31:40 -0000      1.5
+++ src/java/org/apache/commons/configuration/ClassPropertiesConfiguration.java 22 Mar 
2004 17:58:49 -0000
@@ -49,7 +49,7 @@
      *
      * @param baseClass The class providing the FileStream.
      * @param resource The name of the Resource.
-     * @throws IOException Error while loading the properties file
+     * @throws ConfigurationException Error while loading the properties file
      */
     public ClassPropertiesConfiguration(Class baseClass, String resource)
         throws ConfigurationException
@@ -63,11 +63,22 @@
             : baseClass.getClassLoader();
         
         setIncludesAllowed(true);
+
+        InputStream in = null;
+
         try {
-               load(getPropertyStream(resource));
+            in = getPropertyStream(resource);
+               load(in);
         }
         catch (IOException ioe){
                throw new ConfigurationException("Could not load input stream from 
resource " + resource,ioe);
+        }
+        finally {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException e) {}
         }
     }
 
Index: src/java/org/apache/commons/configuration/PropertiesConfiguration.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/configuration/src/java/org/apache/commons/configuration/PropertiesConfiguration.java,v
retrieving revision 1.4
diff -u -r1.4 PropertiesConfiguration.java
--- src/java/org/apache/commons/configuration/PropertiesConfiguration.java      27 Feb 
2004 17:41:35 -0000      1.4
+++ src/java/org/apache/commons/configuration/PropertiesConfiguration.java      22 Mar 
2004 17:58:50 -0000
@@ -16,16 +16,15 @@
  * limitations under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.commons.lang.StringUtils;
-
 /**
  * This is the "classic" Properties loader which loads the values from
  * a single or multiple files (which can be chained with "include =".
@@ -69,25 +68,23 @@
         setIncludesAllowed(false);
     }
 
-
     /**
      * Creates and loads the extended properties from the specified file.
      * The specified file can contain "include = " properties which then
      * are loaded and merged into the properties.
      *
      * @param fileName The name of the Properties File to load.
-     * @throws IOException Error while loading the properties file
+     * @throws ConfigurationException Error while loading the properties file
      */
     public PropertiesConfiguration(String fileName) throws ConfigurationException
     {
-
         load(fileName);
     }
 
     /**
      * Load the properties from the fileName set by setFileName 
      *
-     * @throws IOException
+     * @throws ConfigurationException
      */
     public void load() throws ConfigurationException
     {
@@ -98,16 +95,27 @@
      * Load the properties from the given fileName
      *
      * @param fileName A properties file to load
-     * @throws IOException
+     * @throws ConfigurationException
      */
     public void load(String fileName) throws ConfigurationException
     {
+        InputStream in = null;
+
        try {
-               load(getPropertyStream(fileName));
+            in = getPropertyStream(fileName);
+               load(in);
        }
        catch (IOException ioe){
                throw new ConfigurationException("Could not load from file " + 
fileName,ioe);
        }
+        finally
+        {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException e) {}
+        }
     }
 
     /**

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to