Mattias Reichel created GROOVY-11242:
----------------------------------------
Summary: Stackoverflow error when calling super from overridden
method
Key: GROOVY-11242
URL: https://issues.apache.org/jira/browse/GROOVY-11242
Project: Groovy
Issue Type: Bug
Components: Static compilation
Affects Versions: 3.0.19, 3.0.18, 3.0.17, 3.0.16, 3.0.15, 3.0.14
Reporter: Mattias Reichel
Fix For: 4.0.0-alpha-1
The following script throws Stackoverflow error when calling super.add(Object
o) from overridden add(Object o) (it ends up calling itself). With
@CompileDynamic on the overridden method the code works.
{code:java}
import groovy.transform.CompileStatic
@CompileStatic
class MySet extends DirtyCheckingSet {
MySet(Set delegate, DirtyCheckable entity, String propertyName) {
super(delegate, entity, propertyName)
}
@Override
boolean add(Object o) {
def added = super.add(o) // <-- Offending command
println "Added $o"
return added
}
}
@CompileStatic
class MyEntity implements DirtyCheckable {
String myProperty
}
@CompileStatic
class DirtyCheckingSet extends DirtyCheckingCollection implements Set {
DirtyCheckingSet(Set target, DirtyCheckable parent, String property) {
super(target, parent, property)
}
}
@CompileStatic
trait DirtyCheckable {
void markDirty(String propertyName) {
println "$propertyName marked dirty"
}
}
@CompileStatic
class DirtyCheckingCollection implements Collection {
final @Delegate Collection target
final DirtyCheckable parent
final String property
DirtyCheckingCollection(Collection target, DirtyCheckable parent, String
property) {
this.target = target
this.parent = parent
this.property = property
}
@Override
boolean add(Object o) {
parent.markDirty(property)
target.add(o)
}
}
MySet set = new MySet([] as Set, new MyEntity([myProperty: 'hello']),
'myProperty')
set.add('myProperty')
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)