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

ArrayList.empty works differently in a Pipeline than in Groovy

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: pipeline
    • Labels:
      None
    • Similar Issues:

      Description

      In a Pipeline ArrayList.empty is applied to each element of the list and returns another ArrayList.

      In a normal console Groovy script ArrayList.empty returns a boolean value which answers, whether the list empty or not.

      What is the reason for this difference? Is it expected or a bug? I always thought that when I call Java class method in the Pipeline script it should work like in Java. From this point of view it seems as a bug.

       

      Example:

      def listA = []
      def listB = [ "1", "2", "3" ]
      println('listA.empty=' + listA.empty)
      println('listB.empty=' + listB.empty) 

      Groovy command line output:

      listA.empty=true
      listB.empty=false

      Pipeline output:

      listA.empty=[]
      listB.empty=[false, false, false]

        Attachments

          Activity

          alexander_samoylov Alexander Samoylov created issue -
          alexander_samoylov Alexander Samoylov made changes -
          Field Original Value New Value
          Status Open [ 1 ] In Progress [ 3 ]
          Hide
          alexander_samoylov Alexander Samoylov added a comment -

          In a Pipeline one should use isEmpty() instead of empty.

          Show
          alexander_samoylov Alexander Samoylov added a comment - In a Pipeline one should use isEmpty() instead of empty .
          alexander_samoylov Alexander Samoylov made changes -
          Resolution Not A Defect [ 7 ]
          Status In Progress [ 3 ] Resolved [ 5 ]
          alexander_samoylov Alexander Samoylov made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            alexander_samoylov Alexander Samoylov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: