Details
Description
occurs with 2.5.14 and 2.5.13, but not with 2.5.12 and earlier. reproducible test case attached (testcase.zip).
1) when I try to compile DerivedTrait.groovy with CompileStatic passed via compiler configuration, I get the following NullPointerException:
test_npe# grt DerivedTrait.groovy groovy-2.5.13 >>> a serious error occurred: BUG! exception in phase 'instruction selection' in source unit 'DerivedTrait.groovy' unexpected NullpointerException >>> stacktrace: BUG! exception in phase 'instruction selection' in source unit 'DerivedTrait.groovy' unexpected NullpointerException at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1089) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:640) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:618) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:595) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:574) at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:307) at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:244) at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:167) at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:207) at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:191) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:110) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128) Caused by: java.lang.NullPointerException at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.checkCast(StaticTypeCheckingVisitor.java:3899) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitCastExpression(StaticTypeCheckingVisitor.java:3883) at org.codehaus.groovy.ast.expr.CastExpression.visit(CastExpression.java:85) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallExpression(StaticTypeCheckingVisitor.java:3228) at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethodCallExpression(StaticCompilationVisitor.java:397) at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:68) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBinaryExpression(StaticTypeCheckingVisitor.java:794) at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.java:49) at org.codehaus.groovy.ast.CodeVisitorSupport.visitBooleanExpression(CodeVisitorSupport.java:217) at org.codehaus.groovy.ast.expr.BooleanExpression.visit(BooleanExpression.java:40) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitIfElse(StaticTypeCheckingVisitor.java:3712) at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:41) at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:86) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:106) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBlockStatement(StaticTypeCheckingVisitor.java:3762) at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:110) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:121) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:2117) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:132) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2481) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2439) at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:224) at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1103) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:54) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:401) at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:182) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:405) at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:182) at org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:188) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135) at org.codehaus.groovy.control.customizers.ASTTransformationCustomizer.call(ASTTransformationCustomizer.groovy:297) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1084) ... 15 more
2) when the same is compiled WITHOUT CompileStatic, I still get the error, although a bit different:
test_npe# grt DerivedTrait.groovy groovy-2.5.13 org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during class generation: NPE while processing DerivedTrait.groovy groovy.lang.GroovyRuntimeException: NPE while processing DerivedTrait.groovy at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:304) at org.codehaus.groovy.control.CompilationUnit$18.call(CompilationUnit.java:854) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1084) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:640) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:618) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:595) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:574) at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:307) at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:244) at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:167) at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:207) at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:191) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:110) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128) Caused by: java.lang.NullPointerException at org.codehaus.groovy.ast.ClassNode.isDerivedFrom(ClassNode.java:955) at org.codehaus.groovy.ast.tools.WideningCategories.implementsInterfaceOrSubclassOf(WideningCategories.java:737) at org.codehaus.groovy.classgen.AsmClassGenerator.visitCastExpression(AsmClassGenerator.java:816) at org.codehaus.groovy.ast.expr.CastExpression.visit(CastExpression.java:85) at org.codehaus.groovy.classgen.asm.CallSiteWriter.prepareSiteAndReceiver(CallSiteWriter.java:254) at org.codehaus.groovy.classgen.asm.CallSiteWriter.prepareSiteAndReceiver(CallSiteWriter.java:243) at org.codehaus.groovy.classgen.asm.CallSiteWriter.makeCallSite(CallSiteWriter.java:291) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCachedCall(InvocationWriter.java:352) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:442) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:150) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeInvokeMethodCall(InvocationWriter.java:124) at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:509) at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:846) at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:68) at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.evaluateCompareExpression(BinaryExpressionHelper.java:480) at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.eval(BinaryExpressionHelper.java:133) at org.codehaus.groovy.classgen.AsmClassGenerator.visitBinaryExpression(AsmClassGenerator.java:717) at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.java:49) at org.codehaus.groovy.classgen.AsmClassGenerator.visitBooleanExpression(AsmClassGenerator.java:839) at org.codehaus.groovy.ast.expr.BooleanExpression.visit(BooleanExpression.java:40) at org.codehaus.groovy.classgen.asm.StatementWriter.writeIfElse(StatementWriter.java:316) at org.codehaus.groovy.classgen.asm.OptimizingStatementWriter.writeIfElse(OptimizingStatementWriter.java:324) at org.codehaus.groovy.classgen.AsmClassGenerator.visitIfElse(AsmClassGenerator.java:661) at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:41) at org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:94) at org.codehaus.groovy.classgen.asm.OptimizingStatementWriter.writeBlockStatement(OptimizingStatementWriter.java:206) at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:645) at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:110) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:121) at org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:505) at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:441) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:132) at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethod(AsmClassGenerator.java:586) at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1103) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:54) at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:279) ... 17 more 1 error
compiler configuration file (referenced as npe_test_config.groovy):
withConfig(configuration) {
// ast(groovy.transform.CompileStatic)
}
"grt" is a script that calls compiler:
export JAVA_HOME=/opt/jdk8u275-b01 export GROOVY=/opt/groovy-for-tests/groovy-2.5.13 export IMP_GROOVY=$GROOVY/lib/* export IMP_SCRIPTROOT=/opt/tests export IMP_CLASSPATH=$IMP_GROOVY:$IMP_SCRIPTROOT echo `basename $GROOVY` groovyc -classpath $IMP_CLASSPATH --configscript=npe_test_config.groovy $1