In some of our unit tests we have more than one thread outputting to the console. Once in a while this leads to crashes in output collection as can be seen in this stack trace from a test case:
Exception in thread "pool-3-thread-2" 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 $Proxy4.output(Unknown Source)
at org.gradle.api.internal.tasks.testing.processors.CaptureTestOutputTestResultProcessor$StdOutForwarder.onOutput(CaptureTestOutputTestResultProcessor.java:90)
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:99)
at java.io.PrintStream.write(PrintStream.java:430)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:272)
at sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:85)
at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:168)
at java.io.PrintStream.newLine(PrintStream.java:496)
at java.io.PrintStream.println(PrintStream.java:757)
at org.gradle.util.LinePerThreadBufferingOutputStream.println(LinePerThreadBufferingOutputStream.java:205)
at com.sony.zenobe.core.sample.SimulationSample$SimpleBattery.adaptChargeLevel(SimulationSample.java:82)
at com.sony.zenobe.core.sample.SimulationSample$SimpleBattery.tick(SimulationSample.java:86)
at com.sony.zenobe.core.sample.SimulationSample$SimpleBattery$1.run(SimulationSample.java:71)
at com.sony.zenobe.core.actor.SynchronizingScheduler$SynchronizedRunnable.run(SynchronizingScheduler.java:52)
at com.sony.zenobe.core.scheduler.ASAPScheduler$ScheduledRunnable.run(ASAPScheduler.java:228)
at com.sony.zenobe.core.scheduler.ASAPScheduler$FixedRateScheduledRunnable.run(ASAPScheduler.java:249)
at com.sony.zenobe.core.scheduler.ASAPScheduler$1.run(ASAPScheduler.java:87)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ArrayIndexOutOfBoundsException
at java.lang.String.getChars(String.java:854)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:391)
at java.lang.StringBuilder.append(StringBuilder.java:119)
at org.gradle.api.internal.tasks.testing.junit.JUnitXmlReportGenerator.output(JUnitXmlReportGenerator.java:60)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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)
... 28 more
StringBuilder is not thread-safe. That may be the cause of our symptoms.