maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r398521 - in /maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report: ReporterManager.java XMLReporter.java
Date Mon, 01 May 2006 04:30:57 GMT
Author: brett
Date: Sun Apr 30 21:30:54 2006
New Revision: 398521

URL: http://svn.apache.org/viewcvs?rev=398521&view=rev
Log:
[SUREFIRE-38] fix NPE in reporters if a test errors before it starts

Modified:
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java?rev=398521&r1=398520&r2=398521&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
Sun Apr 30 21:30:54 2006
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.surefire.util.TeeStream;
+import org.codehaus.plexus.util.IOUtil;
 
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
@@ -282,9 +283,10 @@
 
     private void testFailed( ReportEntry reportEntry, String typeError )
     {
-        String stdOutLog = stdOut.toString();
+        // Note that the fields can be null if the test hasn't even started yet (an early
error)
+        String stdOutLog = stdOut != null ? stdOut.toString() : "";
 
-        String stdErrLog = stdErr.toString();
+        String stdErrLog = stdErr != null ? stdErr.toString() : "";
 
         resetStreams();
 
@@ -305,11 +307,18 @@
 
     private void resetStreams()
     {
-        System.setOut( oldOut );
-        System.setErr( oldErr );
+        // Note that the fields can be null if the test hasn't even started yet (an early
error)
+        if ( oldOut != null )
+        {
+            System.setOut( oldOut );
+        }
+        if ( oldErr != null )
+        {
+            System.setErr( oldErr );
+        }
 
-        newOut.close();
-        newErr.close();
+        IOUtil.close( newOut );
+        IOUtil.close( newErr );
     }
 
     public void reset()

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java?rev=398521&r1=398520&r2=398521&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
Sun Apr 30 21:30:54 2006
@@ -183,6 +183,12 @@
 
     private void writeTestProblems( ReportEntry report, String stdOut, String stdErr, String
name )
     {
+        if ( testCase == null )
+        {
+            // This can occur if the error happens before the test starts
+            testStarting( report );
+        }
+
         Xpp3Dom element = createElement( testCase, name );
 
         String stackTrace = getStackTrace( report );



Mime
View raw message