Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10312

MissingMethodException in method with default parameter in trait - regression in 3.0.9

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.0.0-beta-1, 3.0.9
    • 4.0.0-beta-2, 2.5.16, 3.0.10
    • None

    Description

      After switch from 3.0.8 to 3.0.9 Groovy throws at runtime MissingMethodException for static method in a trait called from another trait, but only if a given method has a default parameter.

      A stripped down code to reproduce problem:

      class StaticStaticInTraitProblem implements TLevel1 {
          static void main(String[] args) {
              staticMethodWithDefaultParameter()
          }
      }
      
      trait TLevel1 extends TLevel2 {
          static void staticMethodWithDefaultParameter(String params = "") { //default param is required to make it fail at runtime
              static2() //fails with MissingMethodException: No signature of method: static foobar.TLevel1.static2() is applicable ...
          }
      }
      
      trait TLevel2 {
          static void static2() {}
      }

      A stacktrace:

      Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: static foobar.TLevel1.static2() is applicable for argument types: () values: []
      Possible solutions: wait(), wait(long), split(groovy.lang.Closure), wait(long, int), notify(), stream()
          at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1584)
          at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1570)
          at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:1003)
          at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:180)
          at foobar.TLevel1$Trait$Helper.$static_methodMissing(StaticStaticInTraitProblem2Spec.groovy)
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
          at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.base/java.lang.reflect.Method.invoke(Method.java:567)
          at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
          at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1582)
          at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1570)
          at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:50)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
          at foobar.TLevel1$Trait$Helper.staticMethodWithDefaultParameter(StaticStaticInTraitProblem2Spec.groovy:11)
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
          at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.base/java.lang.reflect.Method.invoke(Method.java:567)
          at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
          at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
          at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:44)
          at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:100)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:217)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:240)
          at foobar.TLevel1$Trait$Helper.staticMethodWithDefaultParameter(StaticStaticInTraitProblem2Spec.groovy)
          at foobar.TLevel1$Trait$Helper$staticMethodWithDefaultParameter.call(Unknown Source)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
          at foobar.StaticStaticInTraitProblem2Spec.staticMethodWithDefaultParameter(StaticStaticInTraitProblem2Spec.groovy)
          at foobar.StaticStaticInTraitProblem2Spec.main(StaticStaticInTraitProblem2Spec.groovy:5) 
       

      Trying to minimize the original case, I reach similar error also with the other construction:

      class StaticInTraitProblem implements StaticTrait {
          static void main(String[] args) {
              staticMethodWithDefaultParameter()
          }
      }
      
      trait StaticTrait {
          public static final String CONSTANT = ""
          static void staticMethodWithDefaultParameter(String params = "") {  //default param is required to make it fail at runtime
              CONSTANT  //Fails with: MissingMethodException: No signature of method: static foobar.StaticTrait.foobar_StaticTrait__CONSTANT$get() is applicable for argument types: () values: []
          }
      }  

      It worked fine with 3.0.8.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              szpak Marcin Zajaczkowski
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: