[MSUREFIRE-1324] Surefire incorrectly suppresses exceptions when closing resources.
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/cc09759a Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/cc09759a Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/cc09759a Branch: refs/heads/SUREFIRE-1322 Commit: cc09759a9adfa1de4ce968fa8745fc305b7c52e3 Parents: d580f67 Author: Christian Schulte <schu...@apache.org> Authored: Sun Jan 8 06:03:13 2017 +0100 Committer: Christian Schulte <schu...@apache.org> Committed: Sun Jan 8 06:03:13 2017 +0100 ---------------------------------------------------------------------- .../surefire/report/StatelessXmlReporter.java | 27 ++++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cc09759a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java index 271d3f0..b846942 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java @@ -125,10 +125,12 @@ public class StatelessXmlReporter getAddMethodEntryList( methodRunHistoryMap, methodEntry ); } - FileOutputStream outputStream = getOutputStream( testSetReportEntry ); - OutputStreamWriter fw = getWriter( outputStream ); + FileOutputStream outputStream = null; + OutputStreamWriter fw = null; try { + outputStream = getOutputStream( testSetReportEntry ); + fw = getWriter( outputStream ); XMLWriter ppw = new PrettyPrintXMLWriter( fw ); ppw.setEncoding( ENCODING ); @@ -239,10 +241,19 @@ public class StatelessXmlReporter } } ppw.endElement(); // TestSuite + + fw.close(); + fw = null; + outputStream = null; + } + catch ( final IOException e ) + { + throw new RuntimeException( "Failure creating report.", e ); } finally { IOUtil.close( fw ); + IOUtil.close( outputStream ); } } @@ -326,7 +337,7 @@ public class StatelessXmlReporter } private static void startTestElement( XMLWriter ppw, WrappedReportEntry report, String reportNameSuffix, - String timeAsString ) + String timeAsString ) throws IOException { ppw.startElement( "testcase" ); ppw.addAttribute( "name", report.getReportName() ); @@ -349,7 +360,7 @@ public class StatelessXmlReporter } private void createTestSuiteElement( XMLWriter ppw, WrappedReportEntry report, TestSetStats testSetStats, - String timeAsString ) + String timeAsString ) throws IOException { ppw.startElement( "testsuite" ); @@ -376,7 +387,7 @@ public class StatelessXmlReporter private static void getTestProblems( OutputStreamWriter outputStreamWriter, XMLWriter ppw, WrappedReportEntry report, boolean trimStackTrace, FileOutputStream fw, - String testErrorType, boolean createOutErrElementsInside ) + String testErrorType, boolean createOutErrElementsInside ) throws IOException { ppw.startElement( testErrorType ); @@ -421,7 +432,7 @@ public class StatelessXmlReporter // Create system-out and system-err elements private static void createOutErrElements( OutputStreamWriter outputStreamWriter, XMLWriter ppw, - WrappedReportEntry report, FileOutputStream fw ) + WrappedReportEntry report, FileOutputStream fw ) throws IOException { EncodingOutputStream eos = new EncodingOutputStream( fw ); addOutputStreamElement( outputStreamWriter, eos, ppw, report.getStdout(), "system-out" ); @@ -431,7 +442,7 @@ public class StatelessXmlReporter private static void addOutputStreamElement( OutputStreamWriter outputStreamWriter, EncodingOutputStream eos, XMLWriter xmlWriter, Utf8RecodingDeferredFileOutputStream utf8RecodingDeferredFileOutputStream, - String name ) + String name ) throws IOException { if ( utf8RecodingDeferredFileOutputStream != null && utf8RecodingDeferredFileOutputStream.getByteCount() > 0 ) { @@ -461,7 +472,7 @@ public class StatelessXmlReporter * * @param xmlWriter The test suite to report to */ - private static void showProperties( XMLWriter xmlWriter ) + private static void showProperties( XMLWriter xmlWriter ) throws IOException { xmlWriter.startElement( "properties" );