Groovy AOP アプローチを使用して Grails プロジェクトを強化しようとしています。ただし、invokeMethod をクロージャーでオーバーライドすると、常に StackOverflowError が発生します。これが私のテストコードです。groovy 2.1.3 でエラーを再現できます。
class A implements GroovyInterceptable
{
void foo(){
System.out.println( "A.foo");
}
}
class B extends A
{
void foo(){
System.out.println( "B.foo");
super.foo();
}
}
def mc = B.metaClass;
mc.invokeMethod = { String name, args ->
// do "before" and/or "around" work here
try {
def value = mc.getMetaMethod(name, args).invoke(delegate, args)
// do "after" work here
return value // or another value
}
catch (e) {
// do "after-throwing" work here
}
}
B b = new B();
b.foo();