Maven Surefire
  1. Maven Surefire
  2. SUREFIRE-848

NPE in org.apache.maven.plugin.surefire.report.AbstractTextReporter

    Details

    • Complexity:
      Intermediate
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      The combination Surefire/JUnit 4 causes a NullPointerException in org.apache.maven.plugin.surefire.report.AbstractTextReporter if one has a RunListener configured which (for whatever reason) throws an exception in its #testRunStarted(Description) method.

      I have attached a dummy project; run `mvn test` to see the problem. The cause of this issue is that AbstractTextReporter initializes its testResults field when AbstractTextReporter#testSetStarting(ReportEntry) is called, which (it seems) doesn't happen until JUnit invokes RunNotifier#fireTestStarted(Description). This is too late, because an exception during the invocation of RunNotifier#fireTestRunStarted(Description) causes AbstractTextReporter#testError(ReportEntry, String, String) to be invoked. The result is an NPE on line 103.

      Stacktrace:

      Exception in thread "ThreadedStreamConsumer" java.lang.NullPointerException
      	at org.apache.maven.plugin.surefire.report.AbstractTextReporter.testError(AbstractTextReporter.java:103)
      	at org.apache.maven.plugin.surefire.report.MulticastingReporter.testError(MulticastingReporter.java:87)
      	at org.apache.maven.plugin.surefire.report.TestSetRunListener.testError(TestSetRunListener.java:150)
      	at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.consumeLine(ForkClient.java:115)
      	at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.run(ThreadedStreamConsumer.java:67)
      	at java.lang.Thread.run(Thread.java:619)
      

      Note that this issue seems to have been the root cause of SUREFIRE-157; the last comment to that ticket also pointed to the late initialisation of the testResults field.

      1. example.tbz
        1 kB
        Stephan Schroevers

        Activity

        Hide
        Stephan Schroevers added a comment -

        Seems I cannot edit the issue. Anyway, I messed up the last link; should have pointed to this comment.

        Also, this issue exacerbates JUnit issue 395.

        Show
        Stephan Schroevers added a comment - Seems I cannot edit the issue. Anyway, I messed up the last link; should have pointed to this comment. Also, this issue exacerbates JUnit issue 395 .
        Hide
        Zemian Deng added a comment -

        I get this same error intermittently on our java project build. We are using maven-surefire-plugin:2.11 with maven-3.0.4. When this happens our build seems to take same amount of time, but the test counts and output are way off.

        Exception in thread "ThreadedStreamConsumer" java.lang.NullPointerException
        at org.apache.maven.surefire.report.AbstractFileReporter.testSetCompleted(AbstractFileReporter.java:111)
        at org.apache.maven.surefire.report.MulticastingReporter.testSetCompleted(MulticastingReporter.java:51)
        at org.apache.maven.surefire.report.TestSetRunListener.testSetCompleted(TestSetRunListener.java:121)
        at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.consumeLine(ForkClient.java:97)
        at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.run(ThreadedStreamConsumer.java:67)
        at java.lang.Thread.run(Thread.java:619)

        Show
        Zemian Deng added a comment - I get this same error intermittently on our java project build. We are using maven-surefire-plugin:2.11 with maven-3.0.4. When this happens our build seems to take same amount of time, but the test counts and output are way off. Exception in thread "ThreadedStreamConsumer" java.lang.NullPointerException at org.apache.maven.surefire.report.AbstractFileReporter.testSetCompleted(AbstractFileReporter.java:111) at org.apache.maven.surefire.report.MulticastingReporter.testSetCompleted(MulticastingReporter.java:51) at org.apache.maven.surefire.report.TestSetRunListener.testSetCompleted(TestSetRunListener.java:121) at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.consumeLine(ForkClient.java:97) at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.run(ThreadedStreamConsumer.java:67) at java.lang.Thread.run(Thread.java:619)
        Hide
        Kristian Rosenvold added a comment -

        Fixed in the reporter refactoring in r1374259

        Show
        Kristian Rosenvold added a comment - Fixed in the reporter refactoring in r1374259

          People

          • Assignee:
            Kristian Rosenvold
            Reporter:
            Stephan Schroevers
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: