[groovy-user] Closure.toString() calls the closure?

41 views
Skip to first unread message

Jan Rudert

unread,
Jun 9, 2009, 12:13:45 PM6/9/09
to us...@groovy.codehaus.org
Hi,

I am using groovy 1.6.3 and have a closure mocking an interface:

Closure failing = {
throw new RuntimeException("for test")
}

MyType instance = failing as MyType


afterwards I call the toString()-method on the object. I see the closure
being executed:

instance.toString()

Here is an snippet from the Exception:


at groovy.lang.Closure.call(Closure.java:279)
at
org.codehaus.groovy.runtime.ConvertedClosure.invokeCustom(ConvertedClosure.java:48)
at
org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:77)
at $Proxy6.toString(Unknown Source)


is that right?


Thank you
Jan

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Roshan Dawrani

unread,
Jun 9, 2009, 1:58:37 PM6/9/09
to GroovyUser
It does look a little weird and it is not really toString() related.

So, in the code, all 3 calls shown result in closure invocation. Not sure what purpose this behavior solves.

==================================

Closure failing = {
      throw new RuntimeException("for test")
}

interface MyType {
    def abc()
    def xyz()

}

MyType instance = failing as MyType

// ****** all 3 calls below result in the closure to be invoked *****
instance.abc()
instance.xyz()
instance.toString()
==================================

Roshan Dawrani

unread,
Jun 9, 2009, 2:51:52 PM6/9/09
to GroovyUser
Can you please open a JIRA for this?

Looks like the fix of GROOVY-2801 has affected the case you have reported.

It was supposed to affect only the case where a map of closures was mapped to an interface. The GROOVY-2801 fix should have avoided the mapping of a single closure to an interface scenario.

Jan Rudert

unread,
Jun 10, 2009, 2:40:25 AM6/10/09
to us...@groovy.codehaus.org
http://jira.codehaus.org/browse/GROOVY-3574

I workaround using a map of closures now.

Thanks for your help!
Jan

Roshan Dawrani schrieb:

Reply all
Reply to author
Forward
0 new messages