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

NPE in inferClosureParameterTypes with CompileStatic and incorrect zero-arg closure

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.15, 2.5.2
    • Fix Version/s: 3.0.0-alpha-4, 2.5.3
    • Component/s: None
    • Labels:
      None

      Description

      The code here is not valid so I don't expect it to actually compile. I'm just reporting the internal compiler error which could be improved to emit a proper user-facing error.

      I accidentally called a zero-argument closure with a method like each or collect.

      @groovy.transform.CompileStatic
      class CompileStaticClosureArgs {
          static void main(String[] args) {
              [0].each { -> }
          }
      }
      >>> a serious error occurred: BUG! exception in phase 'instruction selection' in source unit 'CompileStaticClosureArgs.groovy' unexpected NullpointerException
      >>> stacktrace:
      BUG! exception in phase 'instruction selection' in source unit 'CompileStaticClosureArgs.groovy' unexpected NullpointerException
      at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1092)
      at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:624)
      at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:602)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:579)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
      at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:71)
      at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:227)
      at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:160)
      at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:190)
      at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:174)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:116)
      at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:138)
      Caused by: java.lang.NullPointerException
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.doInferClosureParameterTypes(StaticTypeCheckingVisitor.java:2655)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferClosureParameterTypes(StaticTypeCheckingVisitor.java:2524)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallArguments(StaticTypeCheckingVisitor.java:2490)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallExpression(StaticTypeCheckingVisitor.java:3164)
      at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethodCallExpression(StaticCompilationVisitor.java:397)
      at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:70)
      at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:122)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:196)
      at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
      at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:88)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:166)
      at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:104)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:115)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:1963)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:126)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2318)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2277)
      at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:224)
      at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1081)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:53)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:375)
      at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:182)
      at org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:67)
      at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:152)
      at org.codehaus.groovy.transform.ASTTransformationVisitor$2.call(ASTTransformationVisitor.java:196)
      at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1087)
      ... 15 more

      If @CompileStatic is removed, this correctly fails with a MissingMethodException at runtime.

      groovy.lang.MissingMethodException: No signature of method: CompileStaticClosureArgs$_main_closure1.doCall() is applicable for argument types: (java.lang.Integer) values: [0]

      Thank you for working on Groovy.

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              rtandy Ryan Tandy
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: