From c28ec7da7aefa85051bcb81e0eea06c74e17342a Mon Sep 17 00:00:00 2001 From: "Jesse N. Glick" Date: Mon, 27 Feb 2012 21:43:29 +0000 Subject: [PATCH] #52740: safer stream closing. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1294345 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Javadoc.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java index 8115c7bd9..00a8e1524 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java @@ -1708,31 +1708,34 @@ public class Javadoc extends Task { } File tmpList = null; - BufferedWriter srcListWriter = null; - + FileWriter wr = null; try { /** * Write sourcefiles and package names to a temporary file * if requested. */ + BufferedWriter srcListWriter = null; if (useExternalFile) { tmpList = FILE_UTILS.createTempFile("javadoc", "", null, true, true); toExecute.createArgument() .setValue("@" + tmpList.getAbsolutePath()); - srcListWriter = new BufferedWriter( - new FileWriter(tmpList.getAbsolutePath(), - true)); + wr = new FileWriter(tmpList.getAbsolutePath(), true); + srcListWriter = new BufferedWriter(wr); } doSourceAndPackageNames( toExecute, packagesToDoc, sourceFilesToDoc, useExternalFile, tmpList, srcListWriter); + + if (useExternalFile) { + srcListWriter.flush(); + } } catch (IOException e) { tmpList.delete(); throw new BuildException("Error creating temporary file", e, getLocation()); } finally { - FileUtils.close(srcListWriter); + FileUtils.close(wr); } if (packageList != null) {