Good catch, Conor!  This patch should take care of it.

Thanks,
Magesh

On Tue, 23 Oct 2001 Conor MacNeill wrote :
> [EMAIL PROTECTED] wrote:
> 
> > bodewig     01/10/23 04:49:45
> > 
> >   Modified:    .        WHATSNEW
> >                src/main/org/apache/tools/ant/taskdefs/-
> optional
> >                         PropertyFile.java
> >   Log:
> >   make sure <propertyfile> closes the file it's been 
> reading from.
> >   
> >   Submitted by:     Magesh Umasankar 
> <[EMAIL PROTECTED]>
> >   
> 
> Shouldn't this use the try-finally construction we use 
> elsewhere to 
> guarantee file closing in the face of exceptions?
> 
> Conor
> 
 
Index: PropertyFile.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java,v
retrieving revision 1.7
diff -u -w -r1.7 PropertyFile.java
--- PropertyFile.java   2001/10/23 11:49:45     1.7
+++ PropertyFile.java   2001/10/23 14:09:10
@@ -198,17 +198,15 @@
     {
         // Create the PropertyFile
         m_properties = new Properties();
+        FileInputStream fis = null;
         try
         {
             if (m_propertyfile.exists())
             {
                 log("Updating property file: 
"+m_propertyfile.getAbsolutePath());
-                FileInputStream fis = new FileInputStream(m_propertyfile);
+                fis = new FileInputStream(m_propertyfile);
                 BufferedInputStream bis = new BufferedInputStream(fis);
                 m_properties.load(bis);
-                if (fis != null) {
-                    fis.close();
-                }
             }
             else
             {
@@ -222,6 +220,15 @@
         catch(IOException ioe)
         {
             throw new BuildException(ioe.toString());
+        } finally {
+            try {
+                if (fis != null) {
+                    fis.close();
+                }
+            }
+            catch (IOException ioe1) {
+                //ignore
+            }
         }
     }
--

Reply via email to