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

java.lang.UnsupportedOperationException in set map with each

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None
    • Jenkins ver. 2.60.1

      Pipeline job plugin ver: 2.12.1

       

      Run the code in pipeline job:

      Map buildStatus = ['a':'C', 'b':'N', 'c':'R', 'd':'R']
      List nextBuildBranches = ['c', 'd']
      
      buildStatus << buildStatus.subMap(nextBuildBranches).each { it.value = 'C' }
      
      println buildStatus
      

      I got the error message below:

       

      java.lang.UnsupportedOperationException
      	at java.util.AbstractMap$SimpleImmutableEntry.setValue(AbstractMap.java:797)
      	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)

      but it works in Jenkins scripts console.

       

       

       

          [JENKINS-50997] java.lang.UnsupportedOperationException in set map with each

          Sam Van Oort added a comment -

          abayer any notions?

          Sam Van Oort added a comment - abayer any notions?

          Andrew Bayer added a comment -

          This is due to IteratorHack in workflow-cps, which is how we're able to do iteration over map entries without serialization errors. You'll need to work around this - say, with something like:

          Map buildStatus = ['a':'C', 'b':'N', 'c':'R', 'd':'R']
          List nextBuildBranches = ['c', 'd']
          
          nextBuildBranches.each { b ->
            buildStatus.put(b, "C")
          }
          println buildStatus
          

          Andrew Bayer added a comment - This is due to IteratorHack in workflow-cps , which is how we're able to do iteration over map entries without serialization errors. You'll need to work around this - say, with something like: Map buildStatus = [ 'a' : 'C' , 'b' : 'N' , 'c' : 'R' , 'd' : 'R' ] List nextBuildBranches = [ 'c' , 'd' ] nextBuildBranches.each { b -> buildStatus.put(b, "C" ) } println buildStatus

            Unassigned Unassigned
            hubertli Hubert Li
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: