You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2024/10/01 15:51:00 UTC

[jira] [Created] (GROOVY-11488) STC: NPE for not-instanceof examination

Eric Milles created GROOVY-11488:
------------------------------------

             Summary: STC: NPE for not-instanceof examination
                 Key: GROOVY-11488
                 URL: https://issues.apache.org/jira/browse/GROOVY-11488
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 4.0.23, 3.0.22
            Reporter: Eric Milles
            Assignee: Eric Milles


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

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}}.

{code}
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
{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)