Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.8
-
None
Description
I produced this example as a repro for a bug in generic inference (I think perhaps having to do with the reuse of the generic bound T in Collectors.toMap), but I found that it triggers an NPE in the static compiler. @TypeChecked does not have a problem.
import static java.util.stream.Collectors.toMap import java.util.stream.Stream import groovy.transform.CompileStatic @CompileStatic class GroovyAbc { static class Record { String name Integer quantity } void demo() { Stream.of(new Record(name: 'foo', quantity: 3)) .collect( toMap( Record::getName, Record::getQuantity ) ) } }
[ERROR] groovy.lang.GroovyRuntimeException: NullPointerException while processing GroovyAbc.groovy. /home/christopher/git/path/bugs/GroovyAbc.groovy
[ERROR] at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:294)
[ERROR] at org.codehaus.groovy.control.CompilationUnit$3.call(CompilationUnit.java:797)
[ERROR] at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:942)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:610)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR] at org.codehaus.gmavenplus.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:214)
[ERROR] at org.codehaus.gmavenplus.mojo.AbstractCompileMojo.doCompile(AbstractCompileMojo.java:288)
[ERROR] at org.codehaus.gmavenplus.mojo.CompileTestsMojo.execute(CompileTestsMojo.java:76)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[ERROR] Caused by: java.lang.NullPointerException
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticTypesMethodReferenceExpressionWriter.createParametersWithExactType(StaticTypesMethodReferenceExpressionWriter.java:283)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticTypesMethodReferenceExpressionWriter.writeMethodReferenceExpression(StaticTypesMethodReferenceExpressionWriter.java:107)
[ERROR] at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodReferenceExpression(AsmClassGenerator.java:786)
[ERROR] at org.codehaus.groovy.ast.expr.MethodReferenceExpression.visit(MethodReferenceExpression.java:34)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.visitArgument(StaticInvocationWriter.java:514)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.loadArguments(StaticInvocationWriter.java:461)
[ERROR] at org.codehaus.groovy.classgen.asm.InvocationWriter.writeDirectMethodCall(InvocationWriter.java:208)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeDirectMethodCall(StaticInvocationWriter.java:387)
[ERROR] at org.codehaus.groovy.classgen.asm.InvocationWriter.makeDirectCall(InvocationWriter.java:299)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeDirectCall(StaticInvocationWriter.java:133)
[ERROR] at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:381)
[ERROR] at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:121)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:649)
[ERROR] at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:456)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:140)
[ERROR] at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:844)
[ERROR] at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:76)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.visitArgument(StaticInvocationWriter.java:514)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.loadArguments(StaticInvocationWriter.java:461)
[ERROR] at org.codehaus.groovy.classgen.asm.InvocationWriter.writeDirectMethodCall(InvocationWriter.java:208)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeDirectMethodCall(StaticInvocationWriter.java:387)
[ERROR] at org.codehaus.groovy.classgen.asm.InvocationWriter.makeDirectCall(InvocationWriter.java:299)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeDirectCall(StaticInvocationWriter.java:133)
[ERROR] at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:381)
[ERROR] at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:121)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:649)
[ERROR] at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:456)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:140)
[ERROR] at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:844)
[ERROR] at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:76)
[ERROR] at org.codehaus.groovy.classgen.asm.StatementWriter.writeExpressionStatement(StatementWriter.java:635)
[ERROR] at org.codehaus.groovy.classgen.AsmClassGenerator.visitExpressionStatement(AsmClassGenerator.java:686)
[ERROR] at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
[ERROR] at org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:94)
[ERROR] at org.codehaus.groovy.classgen.asm.sc.StaticTypesStatementWriter.writeBlockStatement(StaticTypesStatementWriter.java:78)
[ERROR] at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:617)
[ERROR] at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
[ERROR] at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:138)
[ERROR] at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:111)
[ERROR] at org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:461)
[ERROR] at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:408)
[ERROR] at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:106)
[ERROR] at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethod(AsmClassGenerator.java:556)
[ERROR] at org.codehaus.groovy.ast.ClassNode.visitMethods(ClassNode.java:1099)
[ERROR] at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1092)
[ERROR] at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)
[ERROR] at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:271)
[ERROR] ... 34 more