Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.8.0
-
Fix Version/s: 1.8.1
-
Component/s: Compiler, primtive opts
-
Labels:
-
Environment:Windows XP / 7
-
Number of attachments :
Description
please compare
http://stackoverflow.com/questions/6419674/groovyinterceptable-does-not-work-on-methods-with-no-arguments
the following class gives the correct output in Groovy < 1.8, in 1.8 it only works if a parameter is added to the nested method.
A workaround is mentioned in the stackoverflow link.
class SimpleFlow implements GroovyInterceptable { def invokeMethod(String name, args) { System.out.println("time before ${name} called: ${new Date()}") def calledMethod = SimpleFlow.metaClass.getMetaMethod(name, args) calledMethod?.invoke(this, args) System.out.println("time after ${name} called: ${new Date()}\n") } void simpleMethod1(){ System.out.println("simpleMethod1() called") simpleMethod2Nested() } // works well when using an argument void simpleMethod2Nested(){ System.out.println("simpleMethod2Nested") } public static void main(String[] args) { def flow = new SimpleFlow() flow.simpleMethod1() } }
actual output:
time before simpleMethod1 called: Tue Jun 21 04:16:41 CEST 2011
simpleMethod1() called
simpleMethod2Nested
time after simpleMethod1 called: Tue Jun 21 04:16:41 CEST 2011
estimated output:
time before simpleMethod1 called: Tue Jun 21 13:32:44 GMT+08:00 2011
simpleMethod1() called
time before simpleMethod2Nested called: Tue Jun 21 13:32:44 GMT+08:00 2011
simpleMethod2Nested
time after simpleMethod2Nested called: Tue Jun 21 13:32:44 GMT+08:00 2011
time after simpleMethod1 called: Tue Jun 21 13:32:44 GMT+08:00 2011
changed formatting