Browse Source

Make sure files get closed even when there is an exception.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268126 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 24 years ago
parent
commit
cfaea6cf8a
1 changed files with 9 additions and 3 deletions
  1. +9
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java

+ 9
- 3
src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java View File

@@ -245,10 +245,10 @@ public class PropertyFile extends Task
*/ */
private void writeFile() throws BuildException private void writeFile() throws BuildException
{ {
BufferedOutputStream bos = null;
try try
{ {
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(m_propertyfile));
bos = new BufferedOutputStream(new FileOutputStream(m_propertyfile));


// Write the message if we have one. // Write the message if we have one.
if (m_comment != null) if (m_comment != null)
@@ -275,12 +275,18 @@ public class PropertyFile extends Task
bos.write(NEWLINE.getBytes()); bos.write(NEWLINE.getBytes());
bos.flush(); bos.flush();
} }
bos.close();
} }
catch (IOException ioe) catch (IOException ioe)
{ {
throw new BuildException(ioe.toString()); throw new BuildException(ioe.toString());
} }
finally {
if (bos != null) {
try {
bos.close();
} catch (IOException ioex) {}
}
}
} }


/* /*


Loading…
Cancel
Save