Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9918

NPE in static compiler when calling pathological method signature

    XMLWordPrintableJSON

Details

    Description

      I'm attempting to call this Java method:

      GraphTraversal<S, E> hasId(final Object id, final Object... otherIds)
      

      which has a particularly annoying signature but implements the expected behavior by explicitly checking whether id instanceof Object[] and Doing The Right Thing. However, I'm using lists, and the static compiler gets terribly confused by this:

      List<String> ids = ['a', 'b']
      inV().hasId(ids as Object[])
      

      In static mode only, this causes an NPE in the compiler (stack trace below). It appears that the compiler can't figure out how to match the method in the presence of the varargs plus a call-site Object[] parameter. This formulation with an explicit cast to Object works:

      inV().hasId((Object) (ids as Object[]))
      
      [ERROR] groovy.lang.GroovyRuntimeException: NullPointerException while processing RemoveVendorsFromGroupHandler.groovy. /home/christopher/RemoveVendorsFromGroupHandler.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$3.call(CompilationUnit.java:813)
      [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.CompileMojo.execute(CompileMojo.java:69)
      [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.StaticInvocationWriter.visitArgument(StaticInvocationWriter.java:498)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.loadArguments(StaticInvocationWriter.java:492)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeDirectMethodCall(InvocationWriter.java:201)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeDirectMethodCall(StaticInvocationWriter.java:387)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeDirectCall(InvocationWriter.java:292)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeDirectCall(StaticInvocationWriter.java:134)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:374)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:117)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:643)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:449)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:141)
      [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:499)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.loadArguments(StaticInvocationWriter.java:465)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeDirectMethodCall(InvocationWriter.java:201)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeDirectMethodCall(StaticInvocationWriter.java:387)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeDirectCall(InvocationWriter.java:292)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeDirectCall(StaticInvocationWriter.java:134)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:374)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:117)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:643)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:449)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:141)
      [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:499)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.loadArguments(StaticInvocationWriter.java:465)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeDirectMethodCall(StaticInvocationWriter.java:307)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeDirectCall(InvocationWriter.java:292)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeDirectCall(StaticInvocationWriter.java:134)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:374)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:117)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:643)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:449)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:141)
      [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$CheckcastReceiverExpression.visit(StaticInvocationWriter.java:695)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeDirectMethodCall(InvocationWriter.java:159)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeDirectMethodCall(StaticInvocationWriter.java:387)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeDirectCall(InvocationWriter.java:292)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeDirectCall(StaticInvocationWriter.java:134)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:374)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:117)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:643)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:449)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:141)
      [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$CheckcastReceiverExpression.visit(StaticInvocationWriter.java:695)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeDirectMethodCall(InvocationWriter.java:159)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeDirectMethodCall(StaticInvocationWriter.java:387)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeDirectCall(InvocationWriter.java:292)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeDirectCall(StaticInvocationWriter.java:134)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:374)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:117)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:643)
      [ERROR]         at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:449)
      [ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:141)
      [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.writeReturn(StatementWriter.java:613)
      [ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitReturnStatement(AsmClassGenerator.java:681)
      [ERROR]         at org.codehaus.groovy.ast.stmt.ReturnStatement.visit(ReturnStatement.java:73)
      [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]         ... 35 more
      [ERROR] 
      [
      

      Attachments

        Activity

          People

            emilles Eric Milles
            chrylis Christopher Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h