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

NPE in TypeResolver using <T>, Closure<T> and @CompileStatic

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.0
    • 2.3.10, 2.4.1
    • Static compilation
    • None

    Description

      @CompileStatic with in the following code causes NPE in TypeResolver.

      @CompileStatic
      class ClosureInEachWithCompileStaticIssue {
      
          <T> T tryToExecuteWithFreePort(Closure<T> closure) {
              [1].each {
                  return executeLogicForAvailablePort(closure)
              }
          }
      
          private <T> T executeLogicForAvailablePort(Closure<T> closure) {
              return closure.call()
          }
      
          static void main(String[] args) {
              new ClosureInEachWithCompileStaticIssue().executeLogicForAvailablePort { }
          }
      }
      
      Exception in thread "main" 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 java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:387)
      	at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:116)
      	at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:72)
      	at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:56)
      	at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1163)
      	at java.beans.Introspector.getBeanInfo(Introspector.java:426)
      	at java.beans.Introspector.getBeanInfo(Introspector.java:173)
      	at groovy.lang.MetaClassImpl$15.run(MetaClassImpl.java:3290)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3288)
      	at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3264)
      	at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:251)
      	at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:282)
      	at info.solidsoft.rnd.issue.ClosureInEachWithCompileStaticIssue.$getStaticMetaClass(ClosureInEachWithCompileStaticIssue.groovy)
      	at info.solidsoft.rnd.issue.ClosureInEachWithCompileStaticIssue.<init>(ClosureInEachWithCompileStaticIssue.groovy)
      	at info.solidsoft.rnd.issue.ClosureInEachWithCompileStaticIssue.main(ClosureInEachWithCompileStaticIssue.groovy:19)
      

      It works fine with @TypeChecked. I will provide a failing test case.

      Attachments

        Activity

          People

            melix Cédric Champeau
            szpak Marcin Zajaczkowski
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: