You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Jonathan Cottrill (JIRA)" <ji...@apache.org> on 2018/05/16 15:38:00 UTC
[jira] [Commented] (GROOVY-8587) Calling super in an overridden
method results in MissingMethodException when method indirectly inherited
from trait
[ https://issues.apache.org/jira/browse/GROOVY-8587?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16477586#comment-16477586 ]
Jonathan Cottrill commented on GROOVY-8587:
-------------------------------------------
An ugly workaround is to replace the B.super.doSomething() call with:
{code}
Class.forName(A.name + '$Trait$Helper').getMethod("doSomething", A).invoke(A, this)
{code}
> 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:
> {code:groovy}
> 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()
> }
> }
> {code}
> Although this compiles fine, a MissingMethodException is thrown at runtime:
> {code}
> 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)
> {code}
> There appears to be no way to override a method from a trait that was implemented in a "supertrait" and delegate to the original implementation.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)