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

NPE from CpsCallableInvocation.<init> when passing null to one-arg method

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • pipeline

      I was observing the following behavior:

      This works:

      node("master") {
          testMethod(null, new Object())
      }
      
      def testMethod(myparameter,mysecondparameter) {
       echo "test"
      }
      

      This fails:

      node("master") {
          testMethod(null)
      }
      
      def testMethod(myparameter) {
       echo "test"
      }
      

      I was expecting that it should be possible to pass in a single parameter with a null value.

          [JENKINS-29990] NPE from CpsCallableInvocation.<init> when passing null to one-arg method

          Jesse Glick added a comment -
          java.lang.NullPointerException
          	at java.util.Objects.requireNonNull(Objects.java:203)
          	at java.util.Arrays$ArrayList.<init>(Arrays.java:3813)
          	at java.util.Arrays.asList(Arrays.java:3800)
          	at com.cloudbees.groovy.cps.impl.CpsCallableInvocation.<init>(CpsCallableInvocation.java:27)
          	at …
          	at WorkflowScript.testMethod(WorkflowScript)
          	at …
          

          Groovy apparently thinks it is a good idea to pass null rather than [null], which the CPS engine was not expecting. I think this is a varargs issue: null is ambiguous in Java, too, if you have a varargs method, and everything in Groovy is pretty loose and undocumented.

          Jesse Glick added a comment - java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) at java.util.Arrays$ArrayList.<init>(Arrays.java:3813) at java.util.Arrays.asList(Arrays.java:3800) at com.cloudbees.groovy.cps.impl.CpsCallableInvocation.<init>(CpsCallableInvocation.java:27) at … at WorkflowScript.testMethod(WorkflowScript) at … Groovy apparently thinks it is a good idea to pass null rather than [null] , which the CPS engine was not expecting. I think this is a varargs issue: null is ambiguous in Java, too, if you have a varargs method, and everything in Groovy is pretty loose and undocumented.

          Jesse Glick added a comment -

          Possible duplicate of JENKINS-32062, but need to expand that test case to verify it.

          Jesse Glick added a comment - Possible duplicate of JENKINS-32062 , but need to expand that test case to verify it.

          Jesse Glick added a comment -

          Verified duplicate (or at least fixed when using groovy-cps 1.6).

          Jesse Glick added a comment - Verified duplicate (or at least fixed when using groovy-cps 1.6).

            jglick Jesse Glick
            nexus49 Bastian Echterhoelter
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: