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

NullPointerException in instruction selection when calling parameterized function whose type parameter has an upper bound corresponding to a SAM type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0.18, 4.0.12
    • Static Type Checker
    • None

    Description

      I have the following code

      import java.util.*;
      import java.util.function.*;
      
      class Main {
        static final void test(ArrayDeque<String> y) {
          
          m(y::addFirst);
        }
      
        static <C extends Consumer<String>> void m(C cl) {}
      }
      

      Actual behavior

      The compiler crashes with the following stacktrace:

      >>> a serious error occurred: BUG! exception in phase 'instruction selection' in source unit 'Main.groovy' unexpected NullPointerException
      >>> stacktrace:
      BUG! exception in phase 'instruction selection' in source unit 'Main.groovy' unexpected NullPointerException
              at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:953)
              at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:694)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:668)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:649)
              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
              at org.codehaus.groovy.ast.tools.GenericsUtils.parameterizeSAM(GenericsUtils.java:974)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferClosureParameterTypes(StaticTypeCheckingVisitor.java:3110)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallArguments(StaticTypeCheckingVisitor.java:2904)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitStaticMethodCallExpression(StaticTypeCheckingVisitor.java:2819)
              at org.codehaus.groovy.ast.expr.StaticMethodCallExpression.visit(StaticMethodCallExpression.java:44)
              at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:117)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:212)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitExpressionStatement(StaticTypeCheckingVisitor.java:2217)
              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:175)
              at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:72)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:139)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:118)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.lambda$visitConstructorOrMethod$28(StaticTypeCheckingVisitor.java:2680)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.doWithTypeCheckingExtensions(StaticTypeCheckingVisitor.java:463)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:2680)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:110)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2663)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2642)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitConstructorOrMethod(StaticCompilationVisitor.java:189)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:204)
              at org.codehaus.groovy.ast.ClassNode.visitMethods(ClassNode.java:1144)
              at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1137)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.lambda$visitClass$3(StaticTypeCheckingVisitor.java:499)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.doWithTypeCheckingExtensions(StaticTypeCheckingVisitor.java:463)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:499)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:151)
              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:948)
              ... 8 more
      

      Expected behavior

      Compile successfully

      Notes

      Tested against master (commit: 61f445cf4b1099eb25f770cc0685efb10783b8f1)

      Test case adapted from a program that uses the apache-commons-collections lib:

      import java.util.*;
      import java.util.function.*;
      
      class Main {
        static final void test(Iterator<String> x,
                               ArrayDeque<String> y) {
          
          org.apache.commons.collections4.CollectionUtils.forAllButLastDo(x, y::addFirst);
        }
      
      }
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: