Test failure lead to StackOverflowError within gradle and gradle does not fail the build

(post) #1


I think I found a blocking issue within gradle. A missconfiguration of the dependencies leads to test failure, but gradle terminates successfully. In our case an artifact with some resources was not declared as dependency for the test execution. This leads to test failures, but gradle is running into 2 (!) StackOverflowErrors and terminates the build with SUCCESSFUL. I classify this as an blocking issue, because if there is a failing test, then gradle may not terminate with SUCCESSFUL.
This issue is reproducible with attached small project. This project contains 3 classes: MyTest, XmlParser and InternalError. MyTest implements a test for the XmlParser and should read an XML file. This XML file does not exists during the testRuntime and therefore the test will fail with an exception. In this case the exception will be an instance of InternalError which inherits from RuntimeException and overloads the method getMessage(), The implementation of getMessage throws also an InternalError. This small project was developed just for the use case to reproduce this issue. This issue occurs also in our productive build. ./gradlew test -S -Dorg.gradle.parallel=false --info has produced attached log.

sample.zip (53.7 KB)
log.zip (7.7 KB)

(Benjamin Muschko) #2

It looks like you are overriding the following method in your custom exception type InternalError which leads to the StackOverflowError.

public String getMessage() {
    throw new InternalError("Resource not found!");

There’s no need to override the method as it’s already provided by its parent class. It should also not throw a new exception.

(post) #3

Dear Benjamin,

thank you for your statement. I agree that the
StackOverflowError is a subsequent fault. And I know that is not really
necessary to implement the method getMessage. The sample that I gave was kept
very simple. In our productive source code it is a little bit more complex. But
this is not my point behind the issue.

My issue is following: In this case a task failed and
my expectation is that Gradle terminates therefore with “BUILD FAILED”. But at
least in this use case two StackOverflowError (one during serializing and one
during deserializing Objects) occurred in Gradle AND then gradle terminates
with “BUILD SUCCESSFUL”. My expectation
is that gradle is unsusceptible against such tasks or tests. Otherwise it could lead to situations
where for example CI servers executes regularly the build, gradle terminates every
time with “BUILD SUCCESSFUL”, but in truth there is serious problem with one of
the tasks or source code.

By the way: As part of the migration to gradle of the
build process of another product also a StackOverflowError occurred (compare StackOverflowError during parallel build).
But for this second case the
StackOverflow it is not so easy to create a small sample. And in this second
case all tests could be executed successfully.