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

NPE when using type parameter in trait method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.6
    • 2.3.7
    • groovy-runtime
    • None

    Description

      I'm trying to mix a trait into a Gradle plugin. This works:

      trait PluginUtils {
          abstract Project getProject()
          
          public <T extends Task> T createTask(String name, Class type, Closure<?> config) {
            project.task(name, type: type, config)
          }
      }
      
      class MyPlugin implements Plugin<Project>, PluginUtils {
          Project project
          
          void apply(Project project) {
              this.project = project
              createTask("foo", DefaultTask) {}
          }
      }
      
      apply plugin: MyPlugin
      

      As soon as I change Class to Class<T> in the signature of the createTask method, gradle foo blows up with:

      Caused by: java.lang.NullPointerException
      	at com.sun.beans.TypeResolver.resolve(TypeResolver.java:203)
      	at com.sun.beans.TypeResolver.resolve(TypeResolver.java:218)
      	at com.sun.beans.TypeResolver.resolve(TypeResolver.java:169)
      	at com.sun.beans.TypeResolver.resolve(TypeResolver.java:218)
      	at com.sun.beans.TypeResolver.resolveInClass(TypeResolver.java:96)
      	at MyPlugin.<clinit>(/swd/tmp/traitplugin/build.gradle)
      

      Tested with Gradle 2.1-rc-4/Groovy 2.3.6 and Gradle 2.0/Groovy 2.3.3.

      Attachments

        Activity

          People

            melix Cédric Champeau
            pniederw Peter Niederwieser
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: