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

typechecker NPEs on method from findMethodsWithGenerated, unknown receiver

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.1.2
    • Static Type Checker
    • None

    Description

      In some cases (with AST transforms and with just some methods, see below), if the "methodNotFound" event of a typechecking script extension returns a result of "findMethodsWithGenerated", the typechecker NPEs. By Cédric it is caused by an unknown receiver.

      Note that, if in the same case the script returns [], the compiler does not report an error. It should report unknown method perhaps? I am not sure, the case is somewhat convoluted.

      Test case:

      277 /tmp> <astt.groovy                                                       
      import org.codehaus.groovy.ast.*
      import org.codehaus.groovy.ast.expr.*
      import org.codehaus.groovy.control.*
      import org.codehaus.groovy.transform.*
      @GroovyASTTransformation(phase = CompilePhase.SEMANTIC_ANALYSIS)
      class astt extends ClassCodeExpressionTransformer implements ASTTransformation {
       public Expression transform(final Expression exp) {
         def e=super.transform(exp)
         if (e in PropertyExpression) {
           println "Turning to method: $e.text"
           e=new MethodCallExpression(e.objectExpression,e.propertyAsString,MethodCallExpression.NO_ARGUMENTS)
         }
         e
       }
       SourceUnit sourceUnit
       void visit(ASTNode[] nodes, SourceUnit su) {
         (sourceUnit=su)?.ast?.classes?.each { visitClass(it) }
       }
      }
      278 /tmp> mkdir -p astt/META-INF/services                                                   
      279 /tmp> echo astt > astt/META-INF/services/org.codehaus.groovy.transform.ASTTransformation
      280 /tmp> <tc.groovy                                                                        
      methodNotFound { receiver,name,argList,argTypes,call ->
         println "unresolved method $name: $call.text"
         def mm=typeCheckingVisitor.findMethodsWithGenerated(receiver,name)
         println "visitor -> $mm"
         mm
      }
      281 /tmp> <q.groovy 
      @groovy.transform.TypeChecked(extensions='tc.groovy') class Foo {
         static void foo(Vector oa) {
             oa?.elements
         }
      }
      282 /tmp> groovyc -e -cp astt q.groovy                                                      
      Turning to method: oa?.elements
      unresolved method elements: oa.elements()
      visitor -> [MethodNode@1152296720[java.util.Enumeration elements()]]
      null
      stacktrace:
      java.lang.NullPointerException
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallExpression(StaticTypeCheckingVisitor.java:2088)
      	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:64)
      	at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:69)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:193)
      	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
      	at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:163)
      	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:101)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:112)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:1324)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:1588)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:1561)
      	at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1059)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:164)
      	at org.codehaus.groovy.transform.StaticTypesTransformation.visit(StaticTypesTransformation.java:62)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:132)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor$2.call(ASTTransformationVisitor.java:176)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1036)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:573)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:551)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:528)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:507)
      	at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:59)
      	at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:215)
      	at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:148)
      	at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:178)
      	at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:162)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
      	at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
      283 /tmp> 
      
      283 /tmp> <tc.groovy 
      methodNotFound { receiver,name,argList,argTypes,call ->
         println "unresolved method $name: $call.text"
         def mm=typeCheckingVisitor.findMethodsWithGenerated(receiver,name)
         println "visitor -> $mm"
         []//mm
      }
      284 /tmp> groovyc -e -cp astt q.groovy
      Turning to method: oa?.elements
      unresolved method elements: oa.elements()
      visitor -> [MethodNode@404454518[java.util.Enumeration elements()]]
      285 /tmp> 
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            oc OC
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: