Gradle 2.8 causes StackOverflowError on super call

Gradle 2.8 updates Groovy to 2.4. This seems to bring a problem with calling super method. See Bundle.groovy which extends the Jar task and overrides the copy method. Running this on Gradle 2.7 works as expected. Running on Gradle 2.8 leads to a stackoverflow:

Caused by: java.lang.StackOverflowError
    at aQute.bnd.gradle.Bundle.copy(Bundle.groovy:50)
    at aQute.bnd.gradle.Bundle.copy(Bundle.groovy:50)
    at aQute.bnd.gradle.Bundle.copy(Bundle.groovy:50)
    at aQute.bnd.gradle.Bundle.copy(Bundle.groovy:50)
    at aQute.bnd.gradle.Bundle.copy(Bundle.groovy:50)
    at aQute.bnd.gradle.Bundle.copy(Bundle.groovy:50)
    at aQute.bnd.gradle.Bundle.copy(Bundle.groovy:50)
    at aQute.bnd.gradle.Bundle.copy(Bundle.groovy:50)
    at aQute.bnd.gradle.Bundle.copy(Bundle.groovy:50)

This is a very interesting error. I suspect it is related to the Groovy 2.4 upgrade as there were some changes made there related specifically to bytecode and super methods. That said, I cannot reproduce this error other than creating a class that extends specifically from Jar and calls super(). There is something about that class that is special somehow.

That said you have a couple of options:

  1. Use @CompileStatic on the Bundle class
  2. Recompile the plugin against Groovy 2.4 (upgrade to Gradle 2.8)

I used a variation of option 1. I changed the Bundle class to move the call to super.copy() into a new method that is marked @CompileStatic. This allows the other methods to continue to use the Groovy dynamic language features.

   protected void copy() {
-    super.copy()
+    supercopy()
     buildBundle()
   }
+
+  @CompileStatic
+  private void supercopy() {
+    super.copy()
+  }