[GRADLE-1513] Concurrency Bug With JUnit Test Listener Created: 05/May/11  Updated: 04/Jan/13  Resolved: 12/Nov/12

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-milestone-1
Fix Version/s: 1.3-rc-1

Type: Bug
Reporter: Robert Fischer Assignee: Peter Niederwieser
Resolution: Fixed Votes: 4


 Description   

Looks like JUnitXmlReportGenerator is using a StringBuilder instead of a StringBuffer at around line 59, which is causing it to fail in surprising (and unhelpfully messaged) ways if multiple concurrent JUnit tests write to System.out. Changing back to a StringBuffer will solve this problem.

org.gradle.listener.ListenerNotificationException: Failed to notify test result processor.
at org.gradle.messaging.dispatch.BroadcastDispatch.dispatch(BroadcastDispatch.java:97)
at org.gradle.messaging.dispatch.BroadcastDispatch.dispatch(BroadcastDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:75)
at $Proxy5.output(Unknown Source)
at org.gradle.api.internal.tasks.testing.processors.CaptureTestOutputTestResultProcessor$1.onOutput(CaptureTestOutputTestResultProcessor.java:45)
at org.gradle.logging.internal.DefaultStandardOutputRedirector$WriteAction.execute(DefaultStandardOutputRedirector.java:83)
at org.gradle.logging.internal.DefaultStandardOutputRedirector$WriteAction.execute(DefaultStandardOutputRedirector.java:79)
at org.gradle.util.LineBufferingOutputStream$StringOutput.write(LineBufferingOutputStream.java:147)
at org.gradle.util.LineBufferingOutputStream.flush(LineBufferingOutputStream.java:120)
at org.gradle.util.LineBufferingOutputStream.write(LineBufferingOutputStream.java:92)
at java.io.OutputStream.write(OutputStream.java:116)
at java.io.PrintStream.write(PrintStream.java:480)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
at sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:104)
at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:185)
at java.io.PrintStream.newLine(PrintStream.java:546)
at java.io.PrintStream.println(PrintStream.java:807)
at org.gradle.util.LinePerThreadBufferingOutputStream.println(LinePerThreadBufferingOutputStream.java:205)
at test.TestBase.assertPutOut(TestBase.java:62)
at test.TestBase.assertPutzOut(TestBase.java:49)
at test._001_BinaryIntegerArithmetic$1.test(_001_BinaryIntegerArithmetic.java:17)
at test.TestBase$ParallelTest.call(TestBase.java:80)
at test.TestBase$ParallelTest.call(TestBase.java:76)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ArrayIndexOutOfBoundsException
at java.lang.String.getChars(String.java:863)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:416)
at java.lang.StringBuilder.append(StringBuilder.java:132)
at org.gradle.api.internal.tasks.testing.junit.JUnitXmlReportGenerator.output(JUnitXmlReportGenerator.java:59)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:613)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.BroadcastDispatch.dispatch(BroadcastDispatch.java:88)



 Comments   
Comment by Peter Niederwieser [ 08/May/11 ]

According to Adam, it's a deeper problem. JUnitXmlReportGenerator should be executing in a single threaded context.

Comment by Robert Fischer [ 08/May/11 ]

Seeing as how JUnitXmlReportGenerator is going to pick up anything going to stdout/stderr, that's a pretty major hindrance. Any tips on how to work around/cope with that?

Comment by Pablo Munoz [ 23/Oct/12 ]

We get the same exception with sequential tests that are multi-threaded. Any update on this ticket?

Comment by Szczepan Faber [ 23/Oct/12 ]

Which versions you encounter the problem with?

Comment by Pablo Munoz [ 23/Oct/12 ]

Gradle 1.1-rc2

Generated at Wed Jun 30 11:57:25 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.