Details
Description
I was attempting to create a custom delegate class for a third party library. Researching this, I found the following page:
http://docs.codehaus.org/display/GROOVY/Using+the+Delegating+Meta+Class and followed the "Package Name Convention Solution". That failed and I created issue #GROOVY-2262.
I still needed to try and create a custome delegate class, so I proceeded to try the "InvokeHelper Solution" from the same webpage. When I did, I got different errors. so I removed all of my code and only tried the code from the webpage..
It succeed when run from within eclipse, using groovy 1.1-beta 2, which was included with the eclipse development plugin. But when I ran it from the command line where I had groovy 1.1-rc 1, it failed with a java.lang.StackOverflowError. Attached is the full log of the run from the command line.
Looking at the log, I noticed that it appears to go into a loop until the stack overflows
Snippet of log file:
------------------------
at MyDelegatingMetaClass.invokeMethod(DelegatingMetaClassInvokeHelperTest.groovy:44)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.codehaus.groovy.reflection.CachedMethod.invokeByReflection(CachedMethod.java:107)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:127)
at org.codehaus.groovy.runtime.metaclass.StdMetaMethod.invoke(StdMetaMethod.java:18)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:538)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:749)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:118)
at MyDelegatingMetaClass.invokeMethod(DelegatingMetaClassInvokeHelperTest.groovy:44)
------------------------
the MyDelegatingMetaClass.invokeMethod is the one given on the webpage:
--------------------
public Object invokeMethod(Object a_object, String a_methodName, Object[] a_arguments)
{
return "changed ${super.invokeMethod(a_object, a_methodName, a_arguments)}"
}
-------------------
I also tested it under 1.0, and other versions of groovy 1.1 on a different machine. Here is the summary
Groovy 1.0: Successful
Groovy 1.1-b2: Successful
Groovy 1.1-b3: Failed
Groovy 1.1-rc1: Failed (Log file attached)
Groovy 1.1-rc2: Failed (Unzipped over rc1 installation. May not be valid test case)
So, either the changes to beta 3 broke the feature, or the documentation should be updated on the correct way to use this functionality.