Alexey Vladykin created GROOVY-8112:
---------------------------------------
Summary: NPE in Groovy compiler
Key: GROOVY-8112
URL: https://issues.apache.org/jira/browse/GROOVY-8112
Project: Groovy
Issue Type: Bug
Components: Compiler
Affects Versions: 2.4.9
Environment: Windows 8 x64
Reporter: Alexey Vladykin
The following Groovy script causes NPE at compile time:
{code:java|title=Bug.groovy}
@Grapes([
@Grab("org.slf4j:slf4j-api:1.7.22"),
@Grab("org.apache.kafka:kafka-clients:0.10.2.0")
])
import groovy.transform.Field
import org.apache.kafka.clients.producer.Callback
import org.apache.kafka.clients.producer.KafkaProducer
import org.apache.kafka.clients.producer.ProducerRecord
import org.apache.kafka.clients.producer.RecordMetadata
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@Field static final Logger logger = LoggerFactory.getLogger(Bug.class)
wrapper {
Properties config = new Properties()
KafkaProducer kafkaProducer = new KafkaProducer<>(config)
kafkaProducer.send(new ProducerRecord<>('topic', 'data'), new Callback() {
@Override
void onCompletion(RecordMetadata recordMetadata, Exception e) {
if (e != null) {
logger.error("Error sending to Kafka", e)
}
}
})
}
{code}
Full error message from groovyc:
{code:none}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during class generation: NPE while processing Bug.groovy
groovy.lang.GroovyRuntimeException: NPE while processing Bug.groovy
at
org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:258)
at
org.codehaus.groovy.control.CompilationUnit$16.call(CompilationUnit.java:813)
at
org.codehaus.groovy.control.CompilationUnit$16.call(CompilationUnit.java:830)
at
org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1053)
at
org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
at
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
at
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
at
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:525)
at
org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:61)
at
org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:217)
at
org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:150)
at
org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:180)
at
org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:164)
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:109)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)
Caused by: java.lang.NullPointerException
at
org.codehaus.groovy.classgen.AsmClassGenerator.visitFieldExpression(AsmClassGenerator.java:1049)
at
org.codehaus.groovy.classgen.asm.ClosureWriter.loadReference(ClosureWriter.java:135)
at
org.codehaus.groovy.classgen.asm.InvocationWriter.loadVariableWithReference(InvocationWriter.java:611)
at
org.codehaus.groovy.classgen.asm.InvocationWriter.writeAICCall(InvocationWriter.java:596)
at
org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeConstructor(InvocationWriter.java:571)
at
org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorCallExpression(AsmClassGenerator.java:818)
at
org.codehaus.groovy.ast.expr.ConstructorCallExpression.visit(ConstructorCallExpression.java:46)
at
org.codehaus.groovy.classgen.asm.CallSiteWriter.makeCallSite(CallSiteWriter.java:303)
at
org.codehaus.groovy.classgen.asm.InvocationWriter.makeCachedCall(InvocationWriter.java:307)
at
org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:392)
at
org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:104)
at
org.codehaus.groovy.classgen.asm.InvocationWriter.makeInvokeMethodCall(InvocationWriter.java:88)
at
org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:459)
at
org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:767)
at
org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:66)
at
org.codehaus.groovy.classgen.asm.StatementWriter.writeReturn(StatementWriter.java:589)
at
org.codehaus.groovy.classgen.asm.OptimizingStatementWriter.writeReturn(OptimizingStatementWriter.java:319)
at
org.codehaus.groovy.classgen.AsmClassGenerator.visitReturnStatement(AsmClassGenerator.java:616)
at
org.codehaus.groovy.ast.stmt.ReturnStatement.visit(ReturnStatement.java:49)
at
org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:84)
at
org.codehaus.groovy.classgen.asm.OptimizingStatementWriter.writeBlockStatement(OptimizingStatementWriter.java:158)
at
org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:566)
at
org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71)
at
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:104)
at
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:115)
at
org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:430)
at
org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:387)
at
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:126)
at
org.codehaus.groovy.classgen.AsmClassGenerator.visitMethod(AsmClassGenerator.java:507)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1078)
at
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:53)
at
org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:233)
... 18 more
1 error
{code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)