Gradle reports java.io.StreamCorruptedException and freezes when running tests

I am getting the dreaded java.io.StreamCorruptedException when running Gradle tests. I understand that this happens if you System.exit() in your tests but I’ve searched the source code for instances of System.exit() and haven’t found any so I’m at a loss as to how to fix this problem. There are no stack traces in the test standard streams output. This is blocking me from migrating our Ant build to Gradle.

Using Gradle 1.8, but saw similar things with 1.7

Unexpected exception thrown. org.gradle.messaging.remote.internal.MessageIOException: Could not read message from ‘/0:0:0:0:0:0:0:1:61275’.

at org.gradle.messaging.remote.internal.inet.SocketConnection.receive(SocketConnection.java:88)

at org.gradle.messaging.remote.internal.hub.MessageHub$ConnectionReceive.run(MessageHub.java:230)

at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:744) Caused by: java.io.StreamCorruptedException: unexpected block data

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1364)

at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)

at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)

at org.gradle.messaging.remote.internal.Message$ExceptionPlaceholder.read(Message.java:101)

at org.gradle.messaging.remote.internal.Message$ExceptionPlaceholder.getCause(Message.java:129)

at org.gradle.messaging.remote.internal.Message$ExceptionPlaceholder.read(Message.java:88)

at org.gradle.messaging.remote.internal.Message$ExceptionPlaceholder.getCause(Message.java:129)

at org.gradle.messaging.remote.internal.Message$ExceptionPlaceholder.read(Message.java:88)

at org.gradle.messaging.remote.internal.Message$ExceptionReplacingObjectInputStream.resolveObject(Message.java:166)

at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1398)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)

at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1706)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1344)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)

at org.gradle.messaging.remote.internal.Message.receive(Message.java:38)

at org.gradle.messaging.serialize.kryo.JavaSerializer$JavaReader.read(JavaSerializer.java:50)

at org.gradle.messaging.remote.internal.hub.MethodInvocationSerializer$MethodInvocationReader.readArguments(MethodInvocationSerializer.java:112)

at org.gradle.messaging.remote.internal.hub.MethodInvocationSerializer$MethodInvocationReader.read(MethodInvocationSerializer.java:107)

at org.gradle.messaging.remote.internal.hub.MethodInvocationSerializer$MethodInvocationReader.read(MethodInvocationSerializer.java:87)

at org.gradle.messaging.serialize.kryo.TypeSafeSerializer$1.read(TypeSafeSerializer.java:37)

at org.gradle.messaging.remote.internal.hub.InterHubMessageSerializer$MessageReader.read(InterHubMessageSerializer.java:67)

at org.gradle.messaging.remote.internal.hub.InterHubMessageSerializer$MessageReader.read(InterHubMessageSerializer.java:53)

at org.gradle.messaging.remote.internal.inet.SocketConnection.receive(SocketConnection.java:83)

I have resorted to using Ant junit task

This is hard to diagnose without more information.

Does this happen consistently? Or is it intermittent?

Can you try dissecting your test suite (using include/exclude patterns) to find the test causing this?

It happens consistently on the same test method, but only when it runs together previous tests. When I run the test in isolation, it passes. I can’t send you the whole project because of I don’t own the code. I also noticed this message:

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread “Thread-7”

I’m not sure which process got the OOME, there is no stack trace from it. I have tried to simulate OOM condition but haven’t managed to reproduce. Will continue to try to isolate this failure.

Here is a simple example that just uses ‘System.exit()’ to solicit a similar error from Gradle: https://github.com/ramonza/gradle-stream-corrupted

I’ve narrowed it down to a particular exception from Hector (the Cassandra client library). From the github project above, execute:

./gradlew test -Dtest.single=ThrowHectorExceptionTest

‘OutOfMemoryError’ was a red herring.

Found the cause of this: https://github.com/gradle/gradle/pull/214