groovy
  1. groovy
  2. GROOVY-3712

@Delegate produces invalid class file

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.7-rc-2
    • Fix Version/s: 1.6.8, 1.7.1, 1.8-beta-1
    • Component/s: Compiler
    • Labels:
      None
    • Environment:
      Mac OS 10.5.8
      Java 1.5.0_19
    • Testcase included:
      yes
    • Number of attachments :
      5

      Description

      org/spockframework/Foob.groovy:

      package org.spockframework
      
      class Foob {
        def doit() { println "foob" }
      }
      

      org/spockframework/compiler/Barb.groovy:

      package org.spockframework.compiler
      
      import org.spockframework.Foob
      
      class Barb {
        @Delegate Foob foob
      
        static void main(String[] args) {
          new Barb().barb()
        }
      
        def barb() {
          this.doit()
        }
      }
      

      When I run the main method, I get:

      Exception in thread "main" java.lang.ClassFormatError: Repetitive method name/signature in class file org/spockframework/compiler/Barb
      	at java.lang.ClassLoader.defineClass1(Native Method)
      	at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
      	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
      	at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
      	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
      	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
      	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
      

      When I change this.doit() to doit(), I get:

      Exception in thread "main" java.lang.NullPointerException: Cannot invoke method doit() on null object
      	at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
      	at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:751)
      	at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:728)
      	at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:17)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
      	at org.spockframework.compiler.Barb.doit(Barb.groovy)
      	at org.spockframework.compiler.Barb$doit.callCurrent(Unknown Source)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:147)
      	at org.spockframework.compiler.Barb.barb(Barb.groovy:28)
      	at org.spockframework.compiler.Barb$barb.call(Unknown Source)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
      	at org.spockframework.compiler.Barb.main(Barb.groovy:24)
      
      1. 18Dec_3712_17x_Patch.txt
        3 kB
        Roshan Dawrani
      2. 3712_17x_Patch.txt
        3 kB
        Roshan Dawrani
      3. AfterPatch_JavapOutput.txt
        3 kB
        Roshan Dawrani
      4. Barb.class
        7 kB
        Peter Niederwieser
      5. groovy_3712.patch
        0.9 kB
        Andres Almiray

        Activity

        Hide
        Peter Niederwieser added a comment -

        I can confirm that the @Delegate usage in our codebase works fine with trunk.

        Show
        Peter Niederwieser added a comment - I can confirm that the @Delegate usage in our codebase works fine with trunk.
        Hide
        Roshan Dawrani added a comment -

        Fixed.

        Show
        Roshan Dawrani added a comment - Fixed.
        Hide
        Peter Niederwieser added a comment -

        Thanks Roshan. This won't go into 1.7.0?! I have yet to see a real-world usage of @Delegate that works without this fix.

        Show
        Peter Niederwieser added a comment - Thanks Roshan. This won't go into 1.7.0?! I have yet to see a real-world usage of @Delegate that works without this fix.
        Hide
        Roshan Dawrani added a comment -

        Guillaume said no for it to go in 1.7.0 in one of the comments here.

        So I did it on all the branches except that.

        Show
        Roshan Dawrani added a comment - Guillaume said no for it to go in 1.7.0 in one of the comments here. So I did it on all the branches except that.
        Hide
        blackdrag blackdrag added a comment -

        it should work fine if the class you delegate to was written in Java or if it is not precompiled Groovy... for example compiling both from source at the same time should not impose a problem

        Show
        blackdrag blackdrag added a comment - it should work fine if the class you delegate to was written in Java or if it is not precompiled Groovy... for example compiling both from source at the same time should not impose a problem

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Peter Niederwieser
          • Votes:
            7 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: