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

Builders don't work in Traits

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.3
    • 2.4.4
    • None

    Description

      Traits don't take into account closure delegates, this completely breaks any builder or dynamic behaviour. The following example:

      import groovy.xml.*
      
      trait MyBuilder {
          def build2() {
              def mkp = new MarkupBuilder()
              
              mkp.foo {
                  bar()
              }
          }
      }
      
      class Foo implements MyBuilder {
      
          def build1() {
              def mkp = new MarkupBuilder()
              
              mkp.foo {
                  bar()
              }
          }
      }
      
      foo = new Foo()
      
      foo.build1()
      foo.build2()
      

      Fails with:

      roovy.lang.MissingMethodException: No signature of method: Foo.bar() is applicable for argument types: () values: []
      Possible solutions: wait(), any(), wait(long), use([Ljava.lang.Object;), any(groovy.lang.Closure), is(java.lang.Object)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:56)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:114)
      	at MyBuilder$Trait$Helper$_build2_closure1.doCall(ConsoleScript1:8)
      	at MyBuilder$Trait$Helper$_build2_closure1.doCall(ConsoleScript1)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:606)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:292)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
      	at groovy.lang.Closure.call(Closure.java:423)
      	at groovy.lang.Closure.call(Closure.java:417)
      	at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:143)
      	at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
      	at MyBuilder$Trait$Helper.build2(ConsoleScript1:7)
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            graemerocher1 Graeme Rocher
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: