Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48011

Calling buildInfo.env.collect after buildInfo.append(server.upload(uploadSpec)) causing NPE in Env.java

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: artifactory-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.89
      artifactory-plugin: 2.13.1
    • Similar Issues:

      Description

       

      Hi everyone,

      i just faced very weird issue using buildInfo.append() function.

      I see this exception:

       

      java.lang.NullPointerException at org.jfrog.hudson.pipeline.types.buildInfo.Env.collect(Env.java:102) 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.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:19) at com.mirantis.mcp.MCPArtifactory.uploadBinariesToArtifactory(/var/jenkins_home/jobs/mcp_k8s_test_pipeline/builds/12/libs/pipeline-library/src/com/mirantis/mcp/MCPArtifactory.groovy:234) at 
      ...
      

       

      I using this code

      def uploadBinariesToArtifactoryLocal (ArtifactoryServer server, BuildInfo buildInfo, String uploadSpec,
       Boolean publishInfo = false) {
       println "!!!!!!!!!!!!!!!!! Build Info !!!!!!!!!!!!!!!!!!!!!!!!!!!"
       buildInfo.env.collect()
       println "${buildInfo.env.vars}"
       buildInfo.append(server.upload(uploadSpec))
       println "!!!!!!!!!!!!!!!!! Build Info After Upload Spec !!!!!!!!!!!!!!!!!!!!!!!!!!!"
       buildInfo.env.collect()
       println "${buildInfo.env.vars}"
      if ( publishInfo ) {
       buildInfo.env.capture = true
       buildInfo.env.filter.addInclude("*")
       buildInfo.env.filter.addExclude("*PASSWORD*")
       buildInfo.env.filter.addExclude("*password*")
       buildInfo.env.collect() // this one will fails
       server.publishBuildInfo(buildInfo)
       }
      }
      

       

      So the problematic line is buildInfo.append(server.upload(uploadSpec)).
      If i use this call: server.upload(uploadSpec, buildInfo) it works.

      That probably means the reason of this failure is Env recreation inside append method which caused NPE because CpsScript inside created env is null.

      https://github.com/jenkinsci/artifactory-plugin/blob/master/src/main/java/org/jfrog/hudson/pipeline/types/buildInfo/BuildInfo.java#L97

       

        Attachments

          Activity

          Hide
          yahaviz Yahav Itzhak added a comment -

          Jakub Josef,

          Thanks for reporting this issue.

          We opened HAP-1021 to track this task.

          Show
          yahaviz Yahav Itzhak added a comment - Jakub Josef , Thanks for reporting this issue. We opened  HAP-1021 to track this task.
          Hide
          jakubjosef Jakub Josef added a comment -

          You welcome.

          I fixed this issue using

          server.upload(uploadSpec, buildInfo)

          instead of
          buildInfo.append(server.upload(uploadSpec))
           

          Show
          jakubjosef Jakub Josef added a comment - You welcome. I fixed this issue using server.upload(uploadSpec, buildInfo) instead of buildInfo.append(server.upload(uploadSpec))  
          Hide
          neiljain Neelesh Jain added a comment -

          We are encountering this NullPointerException as well with the following code :

          def buildInfo = Artifactory.newBuildInfo()
          buildInfo.append(server.upload(uploadSpecification))
          buildInfo.env.capture = true
          buildInfo.retention maxBuilds: 10, maxDays: 30, deleteBuildArtifacts: true
          buildInfo.env.collect()
          server.publishBuildInfo(buildInfo)

          Show
          neiljain Neelesh Jain added a comment - We are encountering this NullPointerException as well with the following code : def buildInfo = Artifactory.newBuildInfo() buildInfo.append(server.upload(uploadSpecification)) buildInfo.env.capture = true buildInfo.retention maxBuilds: 10, maxDays: 30, deleteBuildArtifacts: true buildInfo.env.collect() server.publishBuildInfo(buildInfo)
          Hide
          yahaviz Yahav Itzhak added a comment -

          Jakub Josef & Neelesh Jain,

          Jenkins-Artifactory plug-in v2.15.0 which includes a fix for this issue was released.

          Feel free to upgrade.

           

          Show
          yahaviz Yahav Itzhak added a comment - Jakub Josef & Neelesh Jain , Jenkins-Artifactory plug-in v2.15.0 which includes a fix for this issue was released. Feel free to upgrade.  
          Hide
          kerrhome Shannon Kerr added a comment - - edited

          I just got this using Artifactory plugin version 2.16.2 with Jenkins ver. 2.138.1.

          def newBuildInfo = Artifactory.newBuildInfo()
          def buildInfo = newBuildInfo
          buildInfo = (server.download(apiDownloadSpec))
          buildInfo.append = newBuildInfo
          buildInfo.number = version
          node (remoteBuildServer) {
              buildInfo.env.collect()
              server.upload(buildUploadSpec, buildInfo)
          }
          server.publishBuildInfo(buildInfo)

           

          Fails on the buildInfo.env.collect() from above:

          java.lang.NullPointerException
           at org.jfrog.hudson.pipeline.types.buildInfo.Env.collect(Env.java:105)
           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.reflection.CachedMethod.invoke(CachedMethod.java:93)
           at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
           at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
           at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
           at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47)
           at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
           at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
           at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157)
           at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
           at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:155)
           at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155)
           at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:159)
           at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
           at WorkflowScript.run(WorkflowScript:156)
           at ___cps.transform___(Native Method)
           at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
           at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
           at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:77)
           at sun.reflect.GeneratedMethodAccessor624.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:498)
           at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
           at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
           at com.cloudbees.groovy.cps.Next.step(Next.java:83)
           at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
           at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
           at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
           at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
           at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
           at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
           at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
           at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
           at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
           at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:182)
           at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
           at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
           at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
           at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
           at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
           at java.util.concurrent.FutureTask.run(FutureTask.java:266)
           at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
           at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
           at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
           at java.util.concurrent.FutureTask.run(FutureTask.java:266)
           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
           at java.lang.Thread.run(Thread.java:748)
          Show
          kerrhome Shannon Kerr added a comment - - edited I just got this using Artifactory plugin version 2.16.2 with  Jenkins ver. 2.138.1 . def newBuildInfo = Artifactory.newBuildInfo() def buildInfo = newBuildInfo buildInfo = (server.download(apiDownloadSpec)) buildInfo.append = newBuildInfo buildInfo.number = version node (remoteBuildServer) { buildInfo.env.collect() server.upload(buildUploadSpec, buildInfo) } server.publishBuildInfo(buildInfo)   Fails on the buildInfo.env.collect() from above: java.lang.NullPointerException at org.jfrog.hudson.pipeline.types.buildInfo.Env.collect(Env.java:105) 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.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157) at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:155) at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155) at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:159) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17) at WorkflowScript.run(WorkflowScript:156) at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:77) at sun.reflect.GeneratedMethodAccessor624.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72) at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21) at com.cloudbees.groovy.cps.Next.step(Next.java:83) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163) at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122) at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:182) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang. Thread .run( Thread .java:748)

            People

            Assignee:
            yahaviz Yahav Itzhak
            Reporter:
            jakubjosef Jakub Josef
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: