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

NullPointerException in instruction selection phase when having conditionals with lambdas and function references

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.5, 3.0.18
    • Static Type Checker
    • None

    Description

      I have the following program

      import java.util.function.Function;
      
      class Test {
          <T> void m1(Function<T, T> x) {}
      
          double m2(double x) {
              return x;
          }
      
          void m3() {
              m1((true) ? (Double x) -> x : this::m2);
          }
      }
      

      This program crashes the compiler with the following stacktrace

      >>> a serious error occurred: BUG! exception in phase 'instruction selection' in source unit 'test.groovy' unexpected NullPointerException
      >>> stacktrace:
      BUG! exception in phase 'instruction selection' in source unit 'test.groovy' unexpected NullPointerException
              at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:942)
              at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:692)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:666)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:647)
              at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:311)
              at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:240)
              at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:165)
              at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:205)
              at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:189)
      Caused by: java.lang.NullPointerException: Cannot invoke "org.codehaus.groovy.ast.ClassNode.isInterface()" because "type" is null
              at org.codehaus.groovy.ast.ClassHelper.findSAM(ClassHelper.java:563)
              at org.codehaus.groovy.ast.ClassHelper.isSAMType(ClassHelper.java:538)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.checkForTargetType(StaticTypeCheckingVisitor.java:4281)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitValueExpression(StaticTypeCheckingVisitor.java:4255)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitTernaryExpression(StaticTypeCheckingVisitor.java:4226)
              at org.codehaus.groovy.ast.expr.TernaryExpression.visit(TernaryExpression.java:44)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallArguments(StaticTypeCheckingVisitor.java:2824)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallExpression(StaticTypeCheckingVisitor.java:3370)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethodCallExpression(StaticCompilationVisitor.java:420)
              at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:77)
              at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:117)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:204)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitExpressionStatement(StaticTypeCheckingVisitor.java:2205)
              at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:41)
              at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:86)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:168)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBlockStatement(StaticTypeCheckingVisitor.java:3991)
              at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:70)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:142)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:115)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:2604)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:110)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2587)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2566)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitConstructorOrMethod(StaticCompilationVisitor.java:235)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:250)
              at org.codehaus.groovy.ast.ClassNode.visitMethods(ClassNode.java:1131)
              at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1124)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:437)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:196)
              at org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:68)
              at org.codehaus.groovy.control.customizers.ASTTransformationCustomizer.call(ASTTransformationCustomizer.groovy:303)
              at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:937)
      

      Tested against master (commit: b29512397d6ff199976dfb8709c5950e525ac8d6)

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: