Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.22, 4.0.23
-
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