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

STC: calling a closure stored in a property yields an NPE

    Details

      Description

      When you run the following example:

      import groovy.transform.*
      
      class Test {
          Closure c = { it }
          
          @TypeChecked
          void test() {
              c("123")
          }
      }
      
      new Test().test()
      

      An NPE will be thrown:

      java.lang.NullPointerException
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallExpression(StaticTypeCheckingVisitor.java:1717)
      	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:67)
      	at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:69)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:193)
      	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
      	at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:163)
      	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:101)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:112)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:1224)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:1465)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:1439)
      	at org.codehaus.groovy.transform.StaticTypesTransformation.visit(StaticTypesTransformation.java:78)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:132)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor$2.call(ASTTransformationVisitor.java:176)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1027)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:564)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:542)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:519)
      	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:283)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:264)
      	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:613)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:480)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:163)
      	at groovy.lang.GroovyShell$run.call(Unknown Source)
      	at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy:951)
      	at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy)
      	at sun.reflect.GeneratedMethodAccessor242.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
      	at groovy.lang.Closure.call(Closure.java:415)
      	at groovy.lang.Closure.call(Closure.java:409)
      	at groovy.lang.Closure.run(Closure.java:493)
      	at java.lang.Thread.run(Thread.java:680)
      

        Attachments

          Activity

            People

            • Assignee:
              Guillaume Guillaume Delcroix
              Reporter:
              Guillaume Guillaume Delcroix
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: