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

CPS-transformed field initialization including operations causes NPE in transformation

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      So now code like this:

      class C {
        String f = "banana"
        String g = "other " + f
      }
      

      ...will cause a NullPointerException in compilation/transformation - see below for the stacktrace.

      The root cause is that groovy-cps:1.17 started calling SandboxTransfromer.VisitorImpl.visitField to sandbox class fields, but there's no varScope set when those fields are visited, so ScopeTrackingClassCodeExpressionTransformer.isLocalVariable blows up.
       

      [Bitbucket] Notifying commit build result
      [Bitbucket] Build result notified
      java.lang.NullPointerException: Cannot invoke method has() on null object
      at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:58)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
      at org.kohsuke.groovy.sandbox.ScopeTrackingClassCodeExpressionTransformer.isLocalVariable(ScopeTrackingClassCodeExpressionTransformer.groovy:35)
      at org.kohsuke.groovy.sandbox.ScopeTrackingClassCodeExpressionTransformer$isLocalVariable$0.callCurrent(Unknown Source)
      at org.kohsuke.groovy.sandbox.SandboxTransformer$VisitorImpl.innerTransform(SandboxTransformer.groovy:288)
      at org.kohsuke.groovy.sandbox.SandboxTransformer$VisitorImpl.this$6$innerTransform(SandboxTransformer.groovy)
      at sun.reflect.GeneratedMethodAccessor811.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:64)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
      at org.kohsuke.groovy.sandbox.SandboxTransformer$VisitorImpl.transform(SandboxTransformer.groovy:188)
      at org.codehaus.groovy.ast.expr.ExpressionTransformer$transform.callCurrent(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
      at org.codehaus.groovy.ast.expr.ExpressionTransformer$transform.callCurrent(Unknown Source)
      at org.kohsuke.groovy.sandbox.SandboxTransformer$VisitorImpl.innerTransform(SandboxTransformer.groovy:418)
      at org.kohsuke.groovy.sandbox.SandboxTransformer$VisitorImpl.this$6$innerTransform(SandboxTransformer.groovy)
      at sun.reflect.GeneratedMethodAccessor811.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:64)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
      at org.kohsuke.groovy.sandbox.SandboxTransformer$VisitorImpl.transform(SandboxTransformer.groovy:188)
      at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitField(ClassCodeExpressionTransformer.java:68)
      at com.cloudbees.groovy.cps.SandboxCpsTransformer.visitNontransformedField(SandboxCpsTransformer.java:46)
      at com.cloudbees.groovy.cps.CpsTransformer.call(CpsTransformer.java:132)
      at com.cloudbees.groovy.cps.SandboxCpsTransformer.call(SandboxCpsTransformer.java:26)
      at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1065)
      Caused: BUG! exception in phase 'canonicalization' in source unit 'file:.../src/C.groovy' unexpected NullpointerException
      at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1070)
      at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
      at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
      at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
      at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
      at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:129)
      at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:123)
      at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:516)
      at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:479)
      at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:268)
      at hudson.model.ResourceController.execute(ResourceController.java:97)
      at hudson.model.Executor.run(Executor.java:405)
      Finished: FAILURE
      

       

       

        Attachments

          Issue Links

            Activity

            Hide
            vgaidarji Veaceslav Gaidarji added a comment -

            Yes, this is a workaround. I can send you an hpi which can be used temporary until the fix is shipped.

            Show
            vgaidarji Veaceslav Gaidarji added a comment - Yes, this is a workaround. I can send you an hpi which can be used temporary until the fix is shipped.
            Hide
            jglick Jesse Glick added a comment -

            Should be fixed in master branch, pending release. Workaround should be trivial: move initializers to a constructor.

            Show
            jglick Jesse Glick added a comment - Should be fixed in master branch, pending release. Workaround should be trivial: move initializers to a constructor.
            Hide
            jglick Jesse Glick added a comment -

            Fix is actually in script-security 1.30.

            Show
            jglick Jesse Glick added a comment - Fix is actually in script-security 1.30.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            pom.xml
            src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition2Test.java
            http://jenkins-ci.org/commit/workflow-cps-plugin/9751df6154df9e10aeb965efb218cbb31c1f2ee7
            Log:
            Picking up script-security 1.30 release, and demonstrating fix of JENKINS-45629.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: pom.xml src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition2Test.java http://jenkins-ci.org/commit/workflow-cps-plugin/9751df6154df9e10aeb965efb218cbb31c1f2ee7 Log: Picking up script-security 1.30 release, and demonstrating fix of JENKINS-45629 .
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition2Test.java
            http://jenkins-ci.org/commit/workflow-cps-plugin/ebd87bb3e42318e3f0d8a68d00529999fd2fa248
            Log:
            Merge pull request #157 from jglick/final-fields-JENKINS-34599

            JENKINS-34599 JENKINS-45629 Demonstrating fixes

            Compare: https://github.com/jenkinsci/workflow-cps-plugin/compare/bcca2269e873...ebd87bb3e423

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition2Test.java http://jenkins-ci.org/commit/workflow-cps-plugin/ebd87bb3e42318e3f0d8a68d00529999fd2fa248 Log: Merge pull request #157 from jglick/final-fields- JENKINS-34599 JENKINS-34599 JENKINS-45629 Demonstrating fixes Compare: https://github.com/jenkinsci/workflow-cps-plugin/compare/bcca2269e873...ebd87bb3e423

              People

              • Assignee:
                jglick Jesse Glick
                Reporter:
                thawkins83 T.J. Hawkins
              • Votes:
                5 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: