Gradle test runner does not mark junit test case as failed if exception is encountered missing stack trace

issue-acknowledged
gradle-3556

(Clark Stuth) #1

Link to example project: https://github.com/clarkstuth/gradle-failure-scenario

Gradle logged the following stack trace when it encountered a null pointer exception during a junit test execution. The test was not marked as failing and task execution continued as if the test suite was marked as passed.

The test runner also processed the remaining test classes, but did not run any of the contained tests.

In my opinion this should have marked the task as failed, as well as the test itself.

09:20:10.902 [ERROR] [org.gradle.messaging.remote.internal.hub.MessageHubBackedObjectConnection] Unexpected exception thrown.
org.gradle.messaging.remote.internal.MessageIOException: Could not read message from '/127.0.0.1:42312'.
    at org.gradle.messaging.remote.internal.inet.SocketConnection.receive(SocketConnection.java:84)
    at org.gradle.messaging.remote.internal.hub.MessageHub$ConnectionReceive.run(MessageHub.java:235)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at java.lang.Throwable.setStackTrace(Throwable.java:864)
    at org.gradle.messaging.remote.internal.Message$ExceptionPlaceholder.read(Message.java:173)
    at org.gradle.messaging.remote.internal.Message$ExceptionPlaceholder.getCause(Message.java:178)
    at org.gradle.messaging.remote.internal.Message$ExceptionPlaceholder.read(Message.java:135)
    at org.gradle.messaging.remote.internal.Message$ExceptionPlaceholder.getCause(Message.java:178)
    at org.gradle.messaging.remote.internal.Message$ExceptionPlaceholder.read(Message.java:135)
    at org.gradle.messaging.remote.internal.Message$ExceptionReplacingObjectInputStream.resolveObject(Message.java:215)
    at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1401)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
    at org.gradle.messaging.remote.internal.Message.receive(Message.java:57)
    at org.gradle.internal.serialize.BaseSerializerFactory$ThrowableSerializer.read(BaseSerializerFactory.java:148)
    at org.gradle.internal.serialize.BaseSerializerFactory$ThrowableSerializer.read(BaseSerializerFactory.java:146)
    at org.gradle.internal.serialize.DefaultSerializerRegistry$TaggedTypeSerializer.read(DefaultSerializerRegistry.java:85)
    at org.gradle.internal.serialize.ObjectArraySerializer.read(ObjectArraySerializer.java:39)
    at org.gradle.internal.serialize.ObjectArraySerializer.read(ObjectArraySerializer.java:19)
    at org.gradle.internal.serialize.Serializers$StatefulSerializerAdapter$1.read(Serializers.java:36)
    at org.gradle.messaging.remote.internal.hub.MethodInvocationSerializer$MethodInvocationReader.readArguments(MethodInvocationSerializer.java:113)
    at org.gradle.messaging.remote.internal.hub.MethodInvocationSerializer$MethodInvocationReader.read(MethodInvocationSerializer.java:108)
    at org.gradle.messaging.remote.internal.hub.MethodInvocationSerializer$MethodInvocationReader.read(MethodInvocationSerializer.java:88)
    at org.gradle.internal.serialize.kryo.TypeSafeSerializer$1.read(TypeSafeSerializer.java:34)
    at org.gradle.messaging.remote.internal.hub.InterHubMessageSerializer$MessageReader.read(InterHubMessageSerializer.java:66)
    at org.gradle.messaging.remote.internal.hub.InterHubMessageSerializer$MessageReader.read(InterHubMessageSerializer.java:52)
    at org.gradle.messaging.remote.internal.inet.SocketConnection.receive(SocketConnection.java:77)
    ... 6 more

Our test was attempting to mock a complex exception type (using mockito). This exception was wrapped and rethrown by the method under test. It appears as if gradle encountered an error because there was no stack trace on the mocked exception.

Operating System and JVM version: CentOS Linux 7 with openjdk version “1.8.0_101”

------------------------------------------------------------
Gradle 2.13
------------------------------------------------------------

Build time:   2016-04-25 04:10:10 UTC
Build number: none
Revision:     3b427b1481e46232107303c90be7b05079b05b1c

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_101 (Oracle Corporation 25.101-b13)
OS:           Linux 3.10.0-327.28.3.el7.x86_64 amd64

Is this a regression? If yes, which version of Gradle do you know it last worked for?
Also failed on Gradle 2.5, have not tested other versions.


MessageIOException: Could not read message from
(Lari Hotari) #2

Hi @clarkstuth ,

Thanks for reporting the problem and providing a test app the reproduces the problem.
Several users have reported the problem in the past. I was looking for a jira issue and created one since I didn’t find a previous one.

Regards, Lari