[ 
https://issues.apache.org/jira/browse/GROOVY-7866?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149114#comment-18149114
 ] 

Daniel Sun commented on GROOVY-7866:
------------------------------------

Fixed on master; added a regression test in 
460bb91d2d634dbdb39ae80465d15b34b1edc589 
(https://github.com/apache/groovy/commit/460bb91d2d634dbdb39ae80465d15b34b1edc589).

> Groovy tries to invoke an instance method in a static context when using 
> ExpandoMetaClass
> -----------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7866
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7866
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.7
>            Reporter: Graeme Rocher
>            Assignee: Daniel Sun
>            Priority: Major
>              Labels: trait, traits
>             Fix For: 7.0.0-alpha-1
>
>
> The following script:
> {code}
> ExpandoMetaClass.enableGlobally()
> trait Attributes {
>     void attributes(Map attrs) {}
> }    
> class Foo implements Attributes {
>     String attributes
>     static stuff = {
>         attributes foo:"bar"
>     }
> }
> new Foo().attributes(foo:'bar')
> Foo.stuff.call()
> {code}
> Produces 
> {code}
> java.lang.IllegalArgumentException: object is not an instance of declaring 
> class
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:497)
>       at 
> org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
>       at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
>       at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1212)
>       at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1125)
>       at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
>       at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1157)
> {code}
> I debugged the issue and there is some kind of caching logic that is broken. 
> There is a `CachedMethod` instance that is invoked, even though it is not a 
> static method.
> There should never be a case where the `attributes` method from the trait is 
> invoked since it is an instance method and this is a static context. 



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to