Skip to content

Commit 2af192c

Browse files
fix(testrunner): fix null pointer exception in testrunner when event throwable is null (#1833)
And show full stack trace
1 parent 46919df commit 2af192c

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/TestRunner.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import sbt.testing.{Event, EventHandler, Framework, Status, Task}
44
import stryker4s.model.MutantId
55
import stryker4s.testrunner.api.*
66

7+
import java.io.{PrintWriter, StringWriter}
78
import java.util.concurrent.atomic.{AtomicInteger, AtomicReference}
89
import scala.annotation.tailrec
910
import scala.util.control.NonFatal
@@ -116,7 +117,7 @@ class SbtTestInterfaceRunner(context: TestProcessContext) extends TestRunner wit
116117
_ :+ FailedTestDefinition.of(
117118
fullyQualifiedName = event.fullyQualifiedName,
118119
name = testName,
119-
message = toOption(event.throwable()).map(_.getMessage())
120+
message = toOption(event.throwable()).map(throwableToString)
120121
)
121122
)
122123
()
@@ -126,4 +127,16 @@ class SbtTestInterfaceRunner(context: TestProcessContext) extends TestRunner wit
126127
()
127128
}
128129
}
130+
131+
/** Gets the stack trace from a Throwable as a String, including suppressed and cause exceptions.
132+
*
133+
* @see
134+
* https://commons.apache.org/proper/commons-lang/apidocs/src-html/org/apache/commons/lang3/exception/ExceptionUtils.html#line-463
135+
*/
136+
private def throwableToString(throwable: Throwable): String = {
137+
val sw = new StringWriter()
138+
139+
throwable.printStackTrace(new PrintWriter(sw, true))
140+
sw.toString()
141+
}
129142
}

0 commit comments

Comments
 (0)