Groovy bug - Stackoverflow calling super methods
I recently stumbled upon a bug in the version of Groovy that I was working with (Groovy 2.1.5), it's a strange one, that seems to have been solved in Groovy 2.2 but I thought I would post it here in case it was useful to anyone else.The problem is demonstrated in the code below, but the exact use case seems to be having an inheritance structure > 2 classes deep, whereby the method return type changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Grandparent { | |
public Grandparent doStuff( String s ){ | |
println "GP $s" | |
this | |
} | |
} | |
class Parent extends Grandparent{ | |
public Parent doStuff( String s ){ | |
println "P $s " | |
this | |
} | |
} | |
class Child extends Parent{ | |
public Child doStuff( String s ){ | |
println "C $s " | |
super.doStuff(s) | |
this | |
} | |
} | |
Child c = new Child() | |
c.doStuff("Yo") |
The result in running the above code in Groovy 2.1.5 is a StackOverflow - it seems as though Groovy just recursively calls the doStuff() method on Child class until it errors rather than calling the method on the parent class. Running on Groovy 2.2.0+ appears to run correctly.
I posted the question on stackoverflow.com, and it was suggested that it was maybe related to this bug, which has a very re-assuring resolution comment:
looks like the issue was fixed somewhen between 2.2.2 and 2.3.0
0 comments: