[ https://issues.apache.org/jira/browse/SUREFIRE-2232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17805681#comment-17805681 ]
ASF GitHub Bot commented on SUREFIRE-2232: ------------------------------------------ dr29bart opened a new pull request, #716: URL: https://github.com/apache/maven-surefire/pull/716 > A regression bug appeared in 3.0.0-M6: > > A testNG test class has a listener which updates results from SUCCESS to FAILURE: ``` java @Override public void onTestSuccess(ITestResult result) { result.setStatus(ITestResult.FAILURE); result.getTestContext().getPassedTests().removeResult(result); result.getTestContext().getFailedTests().addResult(result); } ``` > Surefire fails to process a failed test result without a throwable and reports 0 total tests. ``` ForkStarter IOException: java.util.NoSuchElementException. org.apache.maven.plugin.surefire.booterclient.output.MultipleFailureException: java.util.NoSuchElementException at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.<init>(ThreadedStreamConsumer.java:59) at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer.<init>(ThreadedStreamConsumer.java:107) at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:546) at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:285) at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:250) ... Suppressed: java.util.NoSuchElementException at java.base/java.util.StringTokenizer.nextToken(StringTokenizer.java:347) at org.apache.maven.plugin.surefire.report.StatelessXmlReporter.getTestProblems(StatelessXmlReporter.java:454) at org.apache.maven.plugin.surefire.report.StatelessXmlReporter.serializeTestClassWithoutRerun(StatelessXmlReporter.java:221) at org.apache.maven.plugin.surefire.report.StatelessXmlReporter.serializeTestClass(StatelessXmlReporter.java:211) at org.apache.maven.plugin.surefire.report.StatelessXmlReporter.testSetCompleted(StatelessXmlReporter.java:161) at org.apache.maven.plugin.surefire.report.StatelessXmlReporter.testSetCompleted(StatelessXmlReporter.java:85) at org.apache.maven.plugin.surefire.report.TestSetRunListener.testSetCompleted(TestSetRunListener.java:193) at org.apache.maven.plugin.surefire.booterclient.output.ForkClient$TestSetCompletedListener.handle(ForkClient.java:143) ``` The fix is to set a hardcoded value - `UndefinedException` as `error type` in case stack trace is empty. <details> <summary>checklist </summary> Following this checklist to help us incorporate your contribution quickly and easily: - [x] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/SUREFIRE) filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes. - [x] Each commit in the pull request should have a meaningful subject line and body. - [x] Format the pull request title like `[SUREFIRE-XXX] - Fixes bug in ApproximateQuantiles`, where you replace `SUREFIRE-XXX` with the appropriate JIRA issue. Best practice is to use the JIRA issue title in the pull request title and in the first line of the commit message. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [x] Run `mvn clean install` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically. - [x] You have run the integration tests successfully (`mvn -Prun-its clean install`). If your pull request is about ~20 lines of code you don't need to sign an [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure please ask on the developers list. To make clear that you license your contribution under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0) you have to acknowledge this by using the following check-box. - [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0) - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). </details> > StatelessXmlReporter fails to process failed result without a throwable > ----------------------------------------------------------------------- > > Key: SUREFIRE-2232 > URL: https://issues.apache.org/jira/browse/SUREFIRE-2232 > Project: Maven Surefire > Issue Type: Bug > Components: Maven Surefire Plugin > Affects Versions: 3.0.0-M6, 3.2.3 > Reporter: Artem Yak > Priority: Minor > Fix For: waiting-for-feedback > > > > A regression bug appeared in 3.0.0-M6: > A testNG test class has a listener which updates results from SUCCESS to > FAILURE: > > {noformat} > @Override > public void onTestSuccess(ITestResult result) { > result.setStatus(ITestResult.FAILURE); > result.getTestContext().getPassedTests().removeResult(result); > result.getTestContext().getFailedTests().addResult(result); > }{noformat} > > Surefire fails to process a failed test result without a throwable and > reports 0 total tests. > {code:java} > ForkStarter IOException: java.util.NoSuchElementException. > org.apache.maven.plugin.surefire.booterclient.output.MultipleFailureException: > java.util.NoSuchElementException > at > org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.<init>(ThreadedStreamConsumer.java:59) > at > org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer.<init>(ThreadedStreamConsumer.java:107) > at > org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:546) > at > org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:285) > at > org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:250) > {code} > > Reproducible unit test. > {code:java} > package org.apache.maven.plugin.surefire.report; > import java.io.File; > import java.util.HashMap; > import java.util.concurrent.atomic.AtomicInteger; > import junit.framework.TestCase; > import > org.apache.maven.plugin.surefire.booterclient.output.DeserializedStacktraceWriter; > import org.apache.maven.surefire.api.report.SimpleReportEntry; > import org.apache.maven.surefire.api.report.StackTraceWriter; > import static org.apache.maven.plugin.surefire.report.ReportEntryType.ERROR; > import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN; > @SuppressWarnings({"ResultOfMethodCallIgnored", "checkstyle:magicnumber"}) > public class StatelessXmlReporter2Test extends TestCase { > private static final String XSD = > > "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd"; > private static final AtomicInteger FOLDER_POSTFIX = new AtomicInteger(); > private File reportDir; > @Override > protected void setUp() throws Exception { > File basedir = new File("."); > File target = new File(basedir.getCanonicalFile(), "target"); > target.mkdir(); > String reportRelDir = getClass().getSimpleName() + "-" + > FOLDER_POSTFIX.incrementAndGet(); > reportDir = new File(target, reportRelDir); > reportDir.mkdir(); > } > @Override > protected void tearDown() { > } > public void testOutputFailedTestWithoutThrowable() { > StackTraceWriter stackTraceWriterOne = new > DeserializedStacktraceWriter(null, null, ""); > WrappedReportEntry testReport = new WrappedReportEntry( > new SimpleReportEntry( > NORMAL_RUN, 1L, getClass().getName(), null, "a test name", > null, stackTraceWriterOne, 5), > ERROR, > 5, > null, > null); > TestSetStats testSetStats = new TestSetStats(false, false); > testSetStats.testError(testReport); > StatelessXmlReporter reporter = new StatelessXmlReporter( > reportDir, null, false, 1, new HashMap<>(), XSD, "3.0", false, > false, false, false); > reporter.testSetCompleted(testReport, testSetStats); > } > } {code} > > > > {code:java} > java.util.NoSuchElementException > at java.base/java.util.StringTokenizer.nextToken(StringTokenizer.java:349) > at > org.apache.maven.plugin.surefire.report.StatelessXmlReporter.getTestProblems(StatelessXmlReporter.java:454) > at > org.apache.maven.plugin.surefire.report.StatelessXmlReporter.serializeTestClassWithRerun(StatelessXmlReporter.java:256) > at > org.apache.maven.plugin.surefire.report.StatelessXmlReporter.serializeTestClass(StatelessXmlReporter.java:207) > at > org.apache.maven.plugin.surefire.report.StatelessXmlReporter.testSetCompleted(StatelessXmlReporter.java:161) > at > org.apache.maven.plugin.surefire.report.StatelessXmlReporter2Test.testOutputFailedTestWithoutThrowable(StatelessXmlReporter2Test.java:72){code} > > > -- This message was sent by Atlassian Jira (v8.20.10#820010)