groovy
  1. groovy
  2. GROOVY-5386

@Delegate - sometimes compilation fails for generic types

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta-2, 1.8.6
    • Fix Version/s: 2.0.5
    • Component/s: Compiler
    • Labels:
      None
    • Environment:
      JVM: 1.6.0_29 Vendor: Apple Inc. OS: Mac OS X
    • Number of attachments :
      1

      Description

      we have some classes using @Delegate on generic classes:

      @Commons
      class FilterList

      { @Delegate List<Map<Dimension, List<String>>> filterList = [] ... }

      Sometime compilation fails with compiler errors like

      BUG! exception in phase 'class generation' in source unit '/Users/andre/Development/Projects/Adternity/grf/grails-app/jobs/com/grf/reports/ScheduledReportExecutionJob.groovy' Type is null. Most probably you let a transform reuse existing ClassNodes with generics information, that is now used in a wrong context. (Use --stacktrace to see the full trace)

      I assume this has to do with DelegateASTTransformation#nonGeneric handling of generic types, which is setting the generic type to null, but it's hard to reproduce the error in a determined way.

        Activity

        Hide
        blackdrag blackdrag added a comment -

        David, I looked a bit more closely at this last stacktrace and AsmClassGenrator line 1090 is not the method isGroovyObject in 2.4. The line org.codehaus.gmaven.runtime.v1_8.ClassCompilerFeature$ClassCompilerImpl.compile let's me believe you are actually using Groovy 1.8 here

        Show
        blackdrag blackdrag added a comment - David, I looked a bit more closely at this last stacktrace and AsmClassGenrator line 1090 is not the method isGroovyObject in 2.4. The line org.codehaus.gmaven.runtime.v1_8.ClassCompilerFeature$ClassCompilerImpl.compile let's me believe you are actually using Groovy 1.8 here
        Hide
        David Smith added a comment - - edited

        That would explain why it works in intellij which is using the maven dependency from the main section of the pom
        but fails to work when using maven to do the compile it is using the gmaven plugin which has a provider set to 1.8, I can change this to 2.0 but still get the bug.

        Is there a gmaven plugin that supports later versions of groovy than 2.0 or an alternative to graven plugin?

        Show
        David Smith added a comment - - edited That would explain why it works in intellij which is using the maven dependency from the main section of the pom but fails to work when using maven to do the compile it is using the gmaven plugin which has a provider set to 1.8, I can change this to 2.0 but still get the bug. Is there a gmaven plugin that supports later versions of groovy than 2.0 or an alternative to graven plugin?
        Hide
        David Smith added a comment -

        I was able to get the code compiled with groovyc rather than gmaven-plugin and the code compiles and runs successfully using 2.4.0-SNAPSHOT

        For info, you can replace your gmaven-plugin with:

                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <configuration>
                                    <tasks>
                                        <taskdef name="Groovydoc" classname="org.codehaus.groovy.ant.Groovydoc">
                                            <classpath>
                                                <path refid="maven.compile.classpath"/>
                                            </classpath>
                                        </taskdef>
        
                                        <Groovydoc destdir="target/apidocs" sourcepath="src/main/groovy" packagenames="**.*"
                                                   use="true"
                                                   windowtitle="Groovydoc" private="false"/>
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>compile</id>
                                <phase>compile</phase>
                                <configuration>
                                    <tasks>
                                        <mkdir dir="${basedir}/src/main/groovy"/>
                                        <taskdef name="groovyc"
                                                 classname="org.codehaus.groovy.ant.Groovyc">
                                            <classpath refid="maven.compile.classpath"/>
                                        </taskdef>
                                        <mkdir dir="${project.build.outputDirectory}"/>
                                        <groovyc destdir="${project.build.outputDirectory}"
                                                 srcdir="${basedir}/src/main/groovy/" listfiles="true">
                                            <classpath refid="maven.compile.classpath"/>
                                        </groovyc>
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>test-compile</id>
                                <phase>test-compile</phase>
                                <configuration>
                                    <tasks>
                                        <mkdir dir="${basedir}/src/test/groovy"/>
                                        <taskdef name="groovyc"
                                                 classname="org.codehaus.groovy.ant.Groovyc">
                                            <classpath refid="maven.test.classpath"/>
                                        </taskdef>
                                        <mkdir dir="${project.build.testOutputDirectory}"/>
                                        <groovyc destdir="${project.build.testOutputDirectory}"
                                                 srcdir="${basedir}/src/test/groovy/" listfiles="true">
                                            <classpath refid="maven.test.classpath"/>
                                        </groovyc>
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
        
                        </executions>
                    </plugin>
        
        Show
        David Smith added a comment - I was able to get the code compiled with groovyc rather than gmaven-plugin and the code compiles and runs successfully using 2.4.0-SNAPSHOT For info, you can replace your gmaven-plugin with: <plugin> <artifactId> maven-antrun-plugin </artifactId> <executions> <execution> <phase> package </phase> <configuration> <tasks> <taskdef name= "Groovydoc" classname= "org.codehaus.groovy.ant.Groovydoc" > <classpath> <path refid= "maven.compile.classpath" /> </classpath> </taskdef> <Groovydoc destdir= "target/apidocs" sourcepath= "src/main/groovy" packagenames= "**.*" use= "true" windowtitle= "Groovydoc" private= "false" /> </tasks> </configuration> <goals> <goal> run </goal> </goals> </execution> <execution> <id> compile </id> <phase> compile </phase> <configuration> <tasks> <mkdir dir= "${basedir}/src/main/groovy" /> <taskdef name= "groovyc" classname= "org.codehaus.groovy.ant.Groovyc" > <classpath refid= "maven.compile.classpath" /> </taskdef> <mkdir dir= "${project.build.outputDirectory}" /> <groovyc destdir= "${project.build.outputDirectory}" srcdir= "${basedir}/src/main/groovy/" listfiles= "true" > <classpath refid= "maven.compile.classpath" /> </groovyc> </tasks> </configuration> <goals> <goal> run </goal> </goals> </execution> <execution> <id> test-compile </id> <phase> test-compile </phase> <configuration> <tasks> <mkdir dir= "${basedir}/src/test/groovy" /> <taskdef name= "groovyc" classname= "org.codehaus.groovy.ant.Groovyc" > <classpath refid= "maven.test.classpath" /> </taskdef> <mkdir dir= "${project.build.testOutputDirectory}" /> <groovyc destdir= "${project.build.testOutputDirectory}" srcdir= "${basedir}/src/test/groovy/" listfiles= "true" > <classpath refid= "maven.test.classpath" /> </groovyc> </tasks> </configuration> <goals> <goal> run </goal> </goals> </execution> </executions> </plugin>
        Hide
        David Smith added a comment - - edited

        For me at least, I find that the following bug

        BUG! exception in phase 'class generation' in source unit 'SimpleTemplateScript1.groovy' Type is null. Most probably you let a transform reuse existing ClassNodes with generics information, that is now used in a wrong context.

        was fixed in 2.0.5
        The issue I was having seems to be with gmaven only supporting compilation up to version 2.0.0

        Show
        David Smith added a comment - - edited For me at least, I find that the following bug BUG! exception in phase 'class generation' in source unit 'SimpleTemplateScript1.groovy' Type is null. Most probably you let a transform reuse existing ClassNodes with generics information, that is now used in a wrong context. was fixed in 2.0.5 The issue I was having seems to be with gmaven only supporting compilation up to version 2.0.0
        Hide
        Pascal Schumacher added a comment -

        @David:

        You can use gmavenplus or the groovy-eclipse-batch compiler instead of gmaven.

        Show
        Pascal Schumacher added a comment - @David: You can use gmavenplus or the groovy-eclipse-batch compiler instead of gmaven.

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Andre Steingress
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: