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

STC NPE when using Collectors.toMap() with a generic result

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.11
    • 4.0.12, 3.0.20
    • Static compilation
    • None

    Description

      I'm not sure what the most specific culprit is, but this reproduces the problem reliably. (The original use case was using DynamoDbTable#index(String), which also returns a generic result.)

      import static java.util.function.Function.identity
      import static java.util.stream.Collectors.toMap
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Bug {
          Bug() {
              ['a'].stream().collect(toMap(identity(), List::of))
          }
      }
      
      [ERROR] Caused by: java.lang.NullPointerException: Cannot load from object array because the return value of "org.codehaus.groovy.ast.ClassNode.getGenericsTypes()" is null
      [ERROR]         at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.isAssignableTo(StaticTypeCheckingSupport.java:496)
      [ERROR]         at org.codehaus.groovy.ast.tools.ParameterUtils.parametersMatch(ParameterUtils.java:74)
      [ERROR]         at org.codehaus.groovy.ast.tools.ParameterUtils.parametersCompatible(ParameterUtils.java:53)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticTypesMethodReferenceExpressionWriter.lambda$findMethodRefMethod$2(StaticTypesMethodReferenceExpressionWriter.java:334)
      [ERROR]         at java.base/java.util.Collection.removeIf(Collection.java:576)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticTypesMethodReferenceExpressionWriter.findMethodRefMethod(StaticTypesMethodReferenceExpressionWriter.java:319)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticTypesMethodReferenceExpressionWriter.writeMethodReferenceExpression(StaticTypesMethodReferenceExpressionWriter.java:104)
      [ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodReferenceExpression(AsmClassGenerator.java:925)
      [ERROR]         at org.codehaus.groovy.ast.expr.MethodReferenceExpression.visit(MethodReferenceExpression.java:34)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.visitArgument(StaticInvocationWriter.java:513)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.loadArguments(StaticInvocationWriter.java:460)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeDirectMethodCall(InvocationWriter.java:213)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeDirectMethodCall(StaticInvocationWriter.java:386)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeDirectCall(InvocationWriter.java:311)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:131)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:125)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:648)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:454)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:136)
      [ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:988)
      [ERROR]         at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:77)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.visitArgument(StaticInvocationWriter.java:513)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.loadArguments(StaticInvocationWriter.java:460)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeDirectMethodCall(InvocationWriter.java:213)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeDirectMethodCall(StaticInvocationWriter.java:386)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeDirectCall(InvocationWriter.java:311)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:131)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:125)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:648)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:454)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:136)
      [ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:988)
      [ERROR]         at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:77)
      [ERROR]         at org.codehaus.groovy.classgen.asm.StatementWriter.writeExpressionStatement(StatementWriter.java:613)
      [ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitExpressionStatement(AsmClassGenerator.java:827)
      [ERROR]         at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:41)
      [ERROR]         at org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:95)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticTypesStatementWriter.writeBlockStatement(StaticTypesStatementWriter.java:77)
      [ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:752)
      [ERROR]         at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:72)
      [ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:611)
      [ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:546)
      [ERROR]         at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructor(ClassCodeVisitorSupport.java:105)
      [ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructor(AsmClassGenerator.java:689)
      [ERROR]         at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1121)
      [ERROR]         at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)
      [ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:365)
      [ERROR]         ... 41 more
      
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              chrylis Christopher Smith
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: