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

STC: NPE for not-instanceof examination

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.22, 4.0.23
    • 3.0.23, 4.0.24
    • None

    Description

      Consider the following:

      @groovy.transform.TypeChecked test(what) {
        if (false) {
          return "false"
        } else if (what !instanceof Object[]) {
          return "!array"
        }
      }
      

      NOTE: The actual code is more complex, but this was enough to trigger the exception.

      The visitClosingBlock method of StaticTypeCheckingVisitor is throwing a NullPointerException due to the !instanceof expression. This is not a problem for Groovy 5 as it has implemented more complete handling of instanceof and !instanceof.

      java.lang.NullPointerException: Cannot invoke "java.util.Map.forEach(java.util.function.BiConsumer)" because "this.typeCheckingContext.ifElseForWhileAssignmentTracker" is null
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.popAssignmentTracking(StaticTypeCheckingVisitor.java:4394)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClosingBlock(StaticTypeCheckingVisitor.java:4268)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBlockStatement(StaticTypeCheckingVisitor.java:4258)
      	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:165)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:138)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:2388)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:133)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2887)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2855)
      	at org.codehaus.groovy.transform.StaticTypesTransformation.visit(StaticTypesTransformation.java:70)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:189)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor.lambda$2(ASTTransformationVisitor.java:284)
      	at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:1040)
      	... 24 more
      

      Attachments

        Activity

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: