Groovy
  1. Groovy
  2. GROOVY-7804

@CompileStatic/@TypeChecked unexpected NullpointerException compiler bug

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.6
    • Fix Version/s: 2.4.7
    • Component/s: Compiler
    • Labels:
      None
    • Environment:
      Windows, jdk1.8.0_60

      Description

      Those code produce compiler bug exception (see below) when @CompileStatic or @TypeChecked is used :

      @CompileStatic
      class KeywordApiMain {
      static main(args) {
      Optional.of("MH370").orElseThrow(

      { -> new RuntimeException() });
      }
      }

      @CompileStatic
      class KeywordApiMain {
      static main(args) {
      Optional.of("MH370").orElseThrow { -> new RuntimeException() }

      ;
      }
      }

      Those code just produce the expected behaviour when compiled and run without the annotation. The workaround is simplifying the code to this :
      class KeywordApiMain {
      static main(args) {
      Optional.of("MH370").orElseThrow

      { new RuntimeException() }

      ;
      }
      }

      The compiler output :
      Error:Groovyc: BUG! exception in phase 'instruction selection' in source unit '-------\XXXX.groovy' unexpected NullpointerException
      at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1060)
      at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
      at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
      at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:62)
      at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:115)
      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:497)
      at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:134)
      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:497)
      at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.runGroovycInThisProcess(InProcessGroovyc.java:156)
      at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.access$000(InProcessGroovyc.java:51)
      at org.jetbrains.jps.incremental.groovy.InProcessGroovyc$1.call(InProcessGroovyc.java:85)
      at org.jetbrains.jps.incremental.groovy.InProcessGroovyc$1.call(InProcessGroovyc.java:82)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
      Caused by: java.lang.NullPointerException
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.extractTypesFromParameters(StaticTypeCheckingVisitor.java:4694)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.convertClosureTypeToSAMType(StaticTypeCheckingVisitor.java:4364)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferReturnTypeGenerics(StaticTypeCheckingVisitor.java:4259)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallExpression(StaticTypeCheckingVisitor.java:2938)
      at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethodCallExpression(StaticCompilationVisitor.java:318)
      at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:66)
      at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:71)
      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:37)
      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:1784)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:126)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2119)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2078)
      at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:165)
      at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1086)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:53)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:249)
      at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:124)
      at org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:63)
      at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:134)
      at org.codehaus.groovy.transform.ASTTransformationVisitor$2.call(ASTTransformationVisitor.java:178)
      at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1055)
      ... 22 more

        Activity

        Hide
        ASF GitHub Bot added a comment -

        GitHub user shils opened a pull request:

        https://github.com/apache/groovy/pull/306

        GROOVY-7804: Coercion of parameterless closure to generic SAM type th…

        …rows NPE during STC

        You can merge this pull request into a Git repository by running:

        $ git pull https://github.com/shils/groovy GROOVY-7804

        Alternatively you can review and apply these changes as the patch at:

        https://github.com/apache/groovy/pull/306.patch

        To close this pull request, make a commit to your master/trunk branch
        with (at least) the following in the commit message:

        This closes #306


        commit 419403ce2d0272c70bd59fe402d9eb38cf3c041f
        Author: Shil Sinha <shils@apache.org>
        Date: 2016-04-06T01:57:46Z

        GROOVY-7804: Coercion of parameterless closure to generic SAM type throws NPE during STC


        Show
        ASF GitHub Bot added a comment - GitHub user shils opened a pull request: https://github.com/apache/groovy/pull/306 GROOVY-7804 : Coercion of parameterless closure to generic SAM type th… …rows NPE during STC You can merge this pull request into a Git repository by running: $ git pull https://github.com/shils/groovy GROOVY-7804 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/groovy/pull/306.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #306 commit 419403ce2d0272c70bd59fe402d9eb38cf3c041f Author: Shil Sinha <shils@apache.org> Date: 2016-04-06T01:57:46Z GROOVY-7804 : Coercion of parameterless closure to generic SAM type throws NPE during STC
        Hide
        ASF GitHub Bot added a comment -

        Github user asfgit closed the pull request at:

        https://github.com/apache/groovy/pull/306

        Show
        ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/groovy/pull/306

          People

          • Assignee:
            Shil Sinha
            Reporter:
            manuc66
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development