Graeme Rocher created GROOVY-7866:
-------------------------------------

             Summary: 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


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
(v6.3.4#6332)

Reply via email to