git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@793528 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -392,6 +392,11 @@ Fixed bugs: | |||||
| which confused some untar implementations. | which confused some untar implementations. | ||||
| Bugzilla Report 47421. | Bugzilla Report 47421. | ||||
| * various places where unchecked PrintWriters could hide exceptions | |||||
| have been revisited to now check the error status or not use a | |||||
| PrintWriter at all. | |||||
| Bugzilla Report 43537. | |||||
| Other changes: | Other changes: | ||||
| -------------- | -------------- | ||||
| * The get task now also follows redirects from http to https | * The get task now also follows redirects from http to https | ||||
| @@ -117,6 +117,10 @@ public class AntStructure extends Task { | |||||
| printer.printTail(out); | printer.printTail(out); | ||||
| if (out.checkError()) { | |||||
| throw new IOException("Encountered an error writing Ant" | |||||
| + " structure"); | |||||
| } | |||||
| } catch (IOException ioe) { | } catch (IOException ioe) { | ||||
| throw new BuildException("Error writing " | throw new BuildException("Error writing " | ||||
| + output.getAbsolutePath(), ioe, getLocation()); | + output.getAbsolutePath(), ioe, getLocation()); | ||||
| @@ -232,7 +232,7 @@ public class Exec extends Task { | |||||
| */ | */ | ||||
| protected void logFlush() { | protected void logFlush() { | ||||
| if (fos != null) { | if (fos != null) { | ||||
| fos.close(); | |||||
| fos.close(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -539,6 +539,9 @@ public class Jar extends Zip { | |||||
| OutputStreamWriter osw = new OutputStreamWriter(baos, Manifest.JAR_ENCODING); | OutputStreamWriter osw = new OutputStreamWriter(baos, Manifest.JAR_ENCODING); | ||||
| PrintWriter writer = new PrintWriter(osw); | PrintWriter writer = new PrintWriter(osw); | ||||
| manifest.write(writer); | manifest.write(writer); | ||||
| if (writer.checkError()) { | |||||
| throw new IOException("Encountered an error writing the manifest"); | |||||
| } | |||||
| writer.close(); | writer.close(); | ||||
| ByteArrayInputStream bais = | ByteArrayInputStream bais = | ||||
| @@ -626,6 +629,9 @@ public class Jar extends Zip { | |||||
| } | } | ||||
| } | } | ||||
| if (writer.checkError()) { | |||||
| throw new IOException("Encountered an error writing jar index"); | |||||
| } | |||||
| writer.close(); | writer.close(); | ||||
| ByteArrayInputStream bais = | ByteArrayInputStream bais = | ||||
| new ByteArrayInputStream(baos.toByteArray()); | new ByteArrayInputStream(baos.toByteArray()); | ||||
| @@ -251,6 +251,9 @@ public class ManifestTask extends Task { | |||||
| OutputStreamWriter osw = new OutputStreamWriter(fos, Manifest.JAR_ENCODING); | OutputStreamWriter osw = new OutputStreamWriter(fos, Manifest.JAR_ENCODING); | ||||
| w = new PrintWriter(osw); | w = new PrintWriter(osw); | ||||
| toWrite.write(w); | toWrite.write(w); | ||||
| if (w.checkError()) { | |||||
| throw new IOException("Encountered an error writing manifest"); | |||||
| } | |||||
| } catch (IOException e) { | } catch (IOException e) { | ||||
| throw new BuildException("Failed to write " + manifestFile, | throw new BuildException("Failed to write " + manifestFile, | ||||
| e, getLocation()); | e, getLocation()); | ||||
| @@ -471,6 +471,10 @@ public class ChangeLogTask extends AbstractCvsTask { | |||||
| final ChangeLogWriter serializer = new ChangeLogWriter(); | final ChangeLogWriter serializer = new ChangeLogWriter(); | ||||
| serializer.printChangeLog(writer, entrySet); | serializer.printChangeLog(writer, entrySet); | ||||
| if (writer.checkError()) { | |||||
| throw new IOException("Encountered an error writing changelog"); | |||||
| } | |||||
| } catch (final UnsupportedEncodingException uee) { | } catch (final UnsupportedEncodingException uee) { | ||||
| getProject().log(uee.toString(), Project.MSG_ERR); | getProject().log(uee.toString(), Project.MSG_ERR); | ||||
| } catch (final IOException ioe) { | } catch (final IOException ioe) { | ||||
| @@ -445,6 +445,9 @@ public class CvsTagDiff extends AbstractCvsTask { | |||||
| } | } | ||||
| DOM_WRITER.closeElement(root, writer, 0, "\t", true); | DOM_WRITER.closeElement(root, writer, 0, "\t", true); | ||||
| writer.flush(); | writer.flush(); | ||||
| if (writer.checkError()) { | |||||
| throw new IOException("Encountered an error writing tagdiff"); | |||||
| } | |||||
| writer.close(); | writer.close(); | ||||
| } catch (UnsupportedEncodingException uee) { | } catch (UnsupportedEncodingException uee) { | ||||
| log(uee.toString(), Project.MSG_ERR); | log(uee.toString(), Project.MSG_ERR); | ||||
| @@ -791,8 +791,10 @@ public class NetRexxC extends MatchingTask { | |||||
| try { | try { | ||||
| StringWriter out = new StringWriter(); | StringWriter out = new StringWriter(); | ||||
| PrintWriter w = null; | |||||
| int rc = | int rc = | ||||
| COM.ibm.netrexx.process.NetRexxC.main(new Rexx(compileArgs), new PrintWriter(out)); | |||||
| COM.ibm.netrexx.process.NetRexxC.main(new Rexx(compileArgs), | |||||
| w = new PrintWriter(out)); | |||||
| String sdir = srcDir.getAbsolutePath(); | String sdir = srcDir.getAbsolutePath(); | ||||
| String ddir = destDir.getAbsolutePath(); | String ddir = destDir.getAbsolutePath(); | ||||
| boolean doReplace = !(sdir.equals(ddir)); | boolean doReplace = !(sdir.equals(ddir)); | ||||
| @@ -839,6 +841,9 @@ public class NetRexxC extends MatchingTask { | |||||
| throw new BuildException("Compile failed, messages should " | throw new BuildException("Compile failed, messages should " | ||||
| + "have been provided."); | + "have been provided."); | ||||
| } | } | ||||
| if (w.checkError()) { | |||||
| throw new IOException("Encountered an error"); | |||||
| } | |||||
| } catch (IOException ioe) { | } catch (IOException ioe) { | ||||
| throw new BuildException("Unexpected IOException while " | throw new BuildException("Unexpected IOException while " | ||||
| + "playing with Strings", ioe); | + "playing with Strings", ioe); | ||||
| @@ -455,6 +455,7 @@ public class JDependTask extends Task { | |||||
| } | } | ||||
| FileWriter fw = null; | FileWriter fw = null; | ||||
| PrintWriter pw = null; | |||||
| if (getOutputFile() != null) { | if (getOutputFile() != null) { | ||||
| try { | try { | ||||
| fw = new FileWriter(getOutputFile().getPath()); | fw = new FileWriter(getOutputFile().getPath()); | ||||
| @@ -464,7 +465,8 @@ public class JDependTask extends Task { | |||||
| log(msg); | log(msg); | ||||
| throw new BuildException(msg); | throw new BuildException(msg); | ||||
| } | } | ||||
| jdepend.setWriter(new PrintWriter(fw)); | |||||
| pw = new PrintWriter(fw); | |||||
| jdepend.setWriter(pw); | |||||
| log("Output to be stored in " + getOutputFile().getPath()); | log("Output to be stored in " + getOutputFile().getPath()); | ||||
| } | } | ||||
| @@ -550,7 +552,14 @@ public class JDependTask extends Task { | |||||
| } | } | ||||
| jdepend.analyze(); | jdepend.analyze(); | ||||
| if (pw.checkError()) { | |||||
| throw new IOException("Encountered an error writing JDepend" | |||||
| + " output"); | |||||
| } | |||||
| } catch (IOException ex) { | |||||
| throw new BuildException(ex); | |||||
| } finally { | } finally { | ||||
| FileUtils.close(pw); | |||||
| FileUtils.close(fw); | FileUtils.close(fw); | ||||
| } | } | ||||
| return SUCCESS; | return SUCCESS; | ||||