Return-Path: X-Original-To: apmail-maven-issues-archive@minotaur.apache.org Delivered-To: apmail-maven-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D4DAB17A1D for ; Tue, 9 Jun 2015 23:52:00 +0000 (UTC) Received: (qmail 73049 invoked by uid 500); 9 Jun 2015 23:52:00 -0000 Delivered-To: apmail-maven-issues-archive@maven.apache.org Received: (qmail 73002 invoked by uid 500); 9 Jun 2015 23:52:00 -0000 Mailing-List: contact issues-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list issues@maven.apache.org Received: (qmail 72991 invoked by uid 99); 9 Jun 2015 23:52:00 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Jun 2015 23:52:00 +0000 Date: Tue, 9 Jun 2015 23:52:00 +0000 (UTC) From: "Tibor Digana (JIRA)" To: issues@maven.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (SUREFIRE-1127) Failsafe project does not fail in verify phase when a test case object errors during initialization MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/SUREFIRE-1127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14579766#comment-14579766 ] Tibor Digana commented on SUREFIRE-1127: ---------------------------------------- If it's so simple fix, pls open the pull request on GitHUb and include the integration test. Thx > Failsafe project does not fail in verify phase when a test case object errors during initialization > --------------------------------------------------------------------------------------------------- > > Key: SUREFIRE-1127 > URL: https://issues.apache.org/jira/browse/SUREFIRE-1127 > Project: Maven Surefire > Issue Type: Bug > Components: Maven Failsafe Plugin > Affects Versions: 2.18 > Environment: JDK 1.8.0_05 on Windows 7 used to recreate > Reporter: Bret Goldsmith > Assignee: Tibor Digana > Attachments: failsafe-test.zip > > > Sample project attached. > When running a "mvn verify" - the attached project will succeed, even though there is an integration test that should obviously fail. > The integration test case does not initialize correctly (it will throw a null pointer exception in one of its object initializers), which should be a test failure and therefore a project failure. > I've traced this down to the fact that the generated failsafe-summary.xml file contains an empty failureMessage element: > {code:xml} > > > 0 > 0 > 0 > 0 > > > {code} > And so the failsafe verifier doesn't consider the project a failure. The message seems to be blank because when the failsafe plugin is writing the results, it uses the org.apache.maven.plugins.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked method to write out the first forked exception, which then calls org.apache.maven.surefire.suite.RunResult.failure() method, which then calls getStackTrace() on the exception. > The getStackTrace() method looks like this: > {code:java} > private static String getStackTrace( Exception e ) > { > if ( e == null ) > { > return null; > } > ByteArrayOutputStream out = new ByteArrayOutputStream(); > PrintWriter pw = new PrintWriter( out ); > e.printStackTrace( pw ); > return new String( out.toByteArray() ); > } > {code} > And it specifically is doing a toBytearray on the output stream without flushing or closing the printwriter first. At least with my JVM 1.8.0_05 version, this seems to be a problem as the printwriter still maintains the trace description in a buffer. > When I put a breakpoint on this and specifically flush or close the printwriter before the toByteArray, the project fails as expected. > I'm not sure why this is failsafe specific, but a surefire version test case (also included in the attachment project) fails appropriately. > I think a simple patch is to update RunResult.java to close the printwriter before getting the resulting stacktrace string. i.e. > {code:java} > private static String getStackTrace( Exception e ) > { > if ( e == null ) > { > return null; > } > ByteArrayOutputStream out = new ByteArrayOutputStream(); > PrintWriter pw = new PrintWriter( out ); > try { > e.printStackTrace( pw ); > } finally { > pw.close(); > } > return new String( out.toByteArray() ); > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)