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

Using Java8 Streams evaluates whole expression to Boolean


    • Similar Issues:


      I'm trying to write a common library building Docker images from Dockerfile. I wrote a reusable global pipeline, where I'm iterating over Dockerfile lines. I tried to use Java 8 Streams, however I ended up with issue potentially related to JENKINS-26307 and JENKINS-42769, which is not related not to Groovy functional features, but Java 8 feature.

       An example code used:

      def getMissingLabels(Map<String, String> labels) {
       ['label1', 'label2', 'label3', 'label4'].stream()
              .filter({ label -> !isLabelDefined(label, labels) })

      Whole stream execution results in "false" boolean result, instead of a list. Even complex streams are passing through, but evaluates to "false". When using more complex stream like:


                  .filter { it.startsWith('LABEL') }
                  .map { it.replaceAll('(LABEL)|"', '') }
                  .map { it.trim() }
                  .map { it.split('=', 2) }
                  { val -> val[0].toLowerCase() },
                  { val -> val[1] }))

      it enters only first filter expression and does not evaluate the rest.

      When replaced functional style code with typical imperative style (for loop) it works.



          Issue Links


            filipowm Mateusz Filipowicz created issue -
            dnusbaum Devin Nusbaum made changes -
            Field Original Value New Value
            Labels pipeline
            dnusbaum Devin Nusbaum made changes -
            Component/s workflow-cps-plugin [ 21713 ]
            Component/s pipeline [ 21692 ]
            dnusbaum Devin Nusbaum made changes -
            Link This issue relates to JENKINS-26481 [ JENKINS-26481 ]
            vivek Vivek Pandey made changes -
            Labels pipeline pipeline pipeline-triaged
            vivek Vivek Pandey made changes -
            Assignee Andrew Bayer [ abayer ]
            abayer Andrew Bayer made changes -
            Assignee Andrew Bayer [ abayer ]


              • Assignee:
                filipowm Mateusz Filipowicz
              • Votes:
                3 Vote for this issue
                5 Start watching this issue


                • Created: