Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.8.2
-
Fix Version/s: 2.0-beta-3
-
Component/s: None
-
Labels:
-
Number of attachments :
Description
The following code will generate a StackOverflowError. It seems "setMetaClass(MetaClass)" is called recursivly, although "super.setMetaClass(MetaClass)" is used. Note that this problem only occures when "Test" has no base class.
class Test {
void setMetaClass(MetaClass metaClass) {
super.setMetaClass(metaClass)
}
}
def obj = new Test()
obj.metaClass = obj.metaClass
On the other hand, the following code works just fine:
class Base {}
class Test extends Base {
void setMetaClass(MetaClass metaClass) {
super.setMetaClass(metaClass)
}
}
def obj = new Test()
obj.metaClass = obj.metaClass
This occurs because in Test, super.setMetaClass is compiled as invokeMethodOnSuperN. As the super class is Object, it ends up with DGM#setMetaClass, which, if the object is a GroovyObject, calls setMetaClass on the object itself. In that case, Test is a GroovyObject, so the method is called recursively, leading to the stack overflow error.