[jira] [Updated] (GROOVY-8587) Calling super in an overridden method results in MissingMethodException when method indirectly inherited from trait

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (GROOVY-8587) Calling super in an overridden method results in MissingMethodException when method indirectly inherited from trait

JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/GROOVY-8587?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Cottrill updated GROOVY-8587:
--------------------------------------
    Description:
Consider the following:

{{trait A {}}
{{    void doSomething() {}}
{{        println "A"}}
{{    }}}
{{ }}}
{{trait B extends A {}}}
{{class C implements B {}}
{{    @Override}}
{{    void doSomething() {}}
{{        B.super.doSomething()}}
{{    }}}
{{    static void main(String[] args) {}}
{{        new C().doSomething()}}
{{    }}}
{{ }}}

Although this compiles fine, a MissingMethodException is thrown at runtime:

{{Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: static B.doSomething() is applicable for argument types: (C) values: [C@12f41634]}}
 \{{ at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1518)}}
 \{{ at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)}}
 \{{ at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:921)}}
 \{{ at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:181)}}
 \{{ at B$Trait$Helper.$static_methodMissing(Bug.groovy)}}
 \{{ 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:498)}}
 \{{ at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)}}
 \{{ at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1516)}}
 \{{ at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)}}
 \{{ at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:52)}}
 \{{ at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)}}
 \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)}}
 \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)}}
 \{{ at C.doSomething(Bug.groovy:12)}}
 \{{ at A$doSomething.call(Unknown Source)}}
 \{{ at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)}}
 \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)}}
 \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)}}
 \{{ at C.main(Bug.groovy:16)}}
 \{{  }}

 

  was:
Consider the following:

trait A {
    void doSomething() {
        println "A"
    }
}

trait B extends A {}

class C implements B {
    @Override
    void doSomething() {
        B.super.doSomething()
    }

    static void main(String[] args) {
        new C().doSomething()
    }
}

Although this compiles fine, a MissingMethodException is thrown at runtime:

{{Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: static B.doSomething() is applicable for argument types: (C) values: [C@12f41634]}}
 \{{ at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1518)}}
 \{{ at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)}}
 \{{ at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:921)}}
 \{{ at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:181)}}
 \{{ at B$Trait$Helper.$static_methodMissing(Bug.groovy)}}
 \{{ 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:498)}}
 \{{ at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)}}
 \{{ at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1516)}}
 \{{ at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)}}
 \{{ at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:52)}}
 \{{ at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)}}
 \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)}}
 \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)}}
 \{{ at C.doSomething(Bug.groovy:12)}}
 \{{ at A$doSomething.call(Unknown Source)}}
 \{{ at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)}}
 \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)}}
 \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)}}
 \{{ at C.main(Bug.groovy:16)}}
 \{{  }}

 


> Calling super in an overridden method results in MissingMethodException when method indirectly inherited from trait
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-8587
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8587
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.15
>            Reporter: Jonathan Cottrill
>            Priority: Major
>
> Consider the following:
> {{trait A {}}
> {{    void doSomething() {}}
> {{        println "A"}}
> {{    }}}
> {{ }}}
> {{trait B extends A {}}}
> {{class C implements B {}}
> {{    @Override}}
> {{    void doSomething() {}}
> {{        B.super.doSomething()}}
> {{    }}}
> {{    static void main(String[] args) {}}
> {{        new C().doSomething()}}
> {{    }}}
> {{ }}}
> Although this compiles fine, a MissingMethodException is thrown at runtime:
> {{Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: static B.doSomething() is applicable for argument types: (C) values: [C@12f41634]}}
>  \{{ at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1518)}}
>  \{{ at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)}}
>  \{{ at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:921)}}
>  \{{ at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:181)}}
>  \{{ at B$Trait$Helper.$static_methodMissing(Bug.groovy)}}
>  \{{ 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:498)}}
>  \{{ at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)}}
>  \{{ at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1516)}}
>  \{{ at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)}}
>  \{{ at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:52)}}
>  \{{ at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)}}
>  \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)}}
>  \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)}}
>  \{{ at C.doSomething(Bug.groovy:12)}}
>  \{{ at A$doSomething.call(Unknown Source)}}
>  \{{ at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)}}
>  \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)}}
>  \{{ at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)}}
>  \{{ at C.main(Bug.groovy:16)}}
>  \{{  }}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)