[
https://issues.apache.org/jira/browse/GROOVY-3708?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-3708.
-----------------------------
> Intercepting an indirectly called method doesn't work.
> ------------------------------------------------------
>
> Key: GROOVY-3708
> URL: https://issues.apache.org/jira/browse/GROOVY-3708
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 1.6.3, 1.6.4, 1.7-beta-1
> Environment: Windows XP SP2, JDK 1.5
> Reporter: Robin Sharma
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-beta-1
>
> Attachments: failingTestForIncorrectInvokeMethodBehaviour.patch,
> possibleFixForInterceptBug.patch
>
>
> 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.
> {code:title=InterceptMe.groovy|borderStyle=solid}
> 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
> }
> }
> {code}
> 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
--
This message was sent by Atlassian Jira
(v8.20.1#820001)