From cfaea6cf8ad35fdd62f047e129aa4e939e486c80 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Wed, 25 Oct 2000 12:05:06 +0000 Subject: [PATCH] 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 --- .../tools/ant/taskdefs/optional/PropertyFile.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java b/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java index 1b554ecb2..65810895b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java @@ -245,10 +245,10 @@ public class PropertyFile extends Task */ private void writeFile() throws BuildException { + BufferedOutputStream bos = null; try { - BufferedOutputStream bos = new BufferedOutputStream( - new FileOutputStream(m_propertyfile)); + bos = new BufferedOutputStream(new FileOutputStream(m_propertyfile)); // Write the message if we have one. if (m_comment != null) @@ -275,12 +275,18 @@ public class PropertyFile extends Task bos.write(NEWLINE.getBytes()); bos.flush(); } - bos.close(); } catch (IOException ioe) { throw new BuildException(ioe.toString()); } + finally { + if (bos != null) { + try { + bos.close(); + } catch (IOException ioex) {} + } + } } /*