Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.6.3, 1.6.4, 1.7-beta-1
-
None
-
Windows XP SP2, JDK 1.5
Description
In the code below, the method to be intercepted, callMeToo, is called internally by another method callMe that is explicitly invoked. When a call to callMe is made, only callMe is intercepted, but the internally called method callMeToo is not intercepted.
InterceptMe.groovy
class InterceptMe { String callMe(String input) { input = "<<" + input + ">>" callMeToo(input) } String callMeToo(String input) { input += "...//\\\\..." println "The input is: $input" input } static void main(args) { InterceptMe.metaClass.invokeMethod = { name, arg -> if(name == "callMeToo") { println "Arguments passed to this method: $arg" } def actualMethod = InterceptMe.metaClass.getMetaMethod(name, arg) actualMethod?.invoke(delegate, arg) } InterceptMe ime = new InterceptMe() ime.callMe("bbbb") // <-- Doesn't print the arguments ime.callMeToo("bbbb") // <-- Prints the arguments } }
Please refer to the following discussion on the Nabble Groovy User Forum for more details:
http://www.nabble.com/How-to-intercept-an-implicitly-called-Method--td25076161.html
-Kodeninja