• Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None

      I get java.io.NotSerializableException: java.util.regex.Matcher on:

      @NonCPS
      def extractLatency(linesArr) {
        latency = [:]
        println "extractLatency"
        for (int j = 0; j < linesArr.size(); j++) {
          line = linesArr[j]
          println("looping over line: $line")
          // Matches lines like: Connect:        0    1   0.1      1       1
          abPattern = /(\w+)\:\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/
      
          def matcher = { (line =~ abPattern) }
      
          if (matcher().size > 1) {
            println("matched")
          }
      
          matcher = null
          abPattern = null
        }
        return latency
      }
      

      If I throw a @NonCPS on the inner def matcher it fixes it.

          [JENKINS-35444] @NonCPS not lexically inherited

          Trevor Hartman created issue -
          Andrew Bayer made changes -
          Assignee Original: Antonio Muñiz [ amuniz ] New: Andrew Bayer [ abayer ]
          Trevor Hartman made changes -
          Description Original: I get java.io.NotSerializableException: java.util.regex.Matcher on:

          {code:groovy}
          @NonCPS
          def extractLatency(linesArr) {
            latency = [:]
            println "extractLatency"
            for (int j = 0; j < linesArr.size(); j++) {
              line = linesArr[j]
              println("looping over line: $line")
              // Matches lines like: Connect: 0 1 0.1 1 1
              abPattern = /(\w+)\:\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/

              def matcher = { (line =~ abPattern) }

              if (matcher().size > 1) {
                println("matched")
              }

              matcher = null
              abPattern = null
            }
            return latency
          }
          {code}

          If I throw a @NonCPS on the inner `def matcher` it fixes it.
          New: I get java.io.NotSerializableException: java.util.regex.Matcher on:

          {code:java}
          @NonCPS
          def extractLatency(linesArr) {
            latency = [:]
            println "extractLatency"
            for (int j = 0; j < linesArr.size(); j++) {
              line = linesArr[j]
              println("looping over line: $line")
              // Matches lines like: Connect: 0 1 0.1 1 1
              abPattern = /(\w+)\:\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/

              def matcher = { (line =~ abPattern) }

              if (matcher().size > 1) {
                println("matched")
              }

              matcher = null
              abPattern = null
            }
            return latency
          }
          {code}

          If I throw a @NonCPS on the inner `def matcher` it fixes it.
          Andrew Bayer made changes -
          Component/s New: workflow-plugin [ 18820 ]
          Component/s Original: pipeline-milestone-step-plugin [ 21448 ]
          Description Original: I get java.io.NotSerializableException: java.util.regex.Matcher on:

          {code:java}
          @NonCPS
          def extractLatency(linesArr) {
            latency = [:]
            println "extractLatency"
            for (int j = 0; j < linesArr.size(); j++) {
              line = linesArr[j]
              println("looping over line: $line")
              // Matches lines like: Connect: 0 1 0.1 1 1
              abPattern = /(\w+)\:\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/

              def matcher = { (line =~ abPattern) }

              if (matcher().size > 1) {
                println("matched")
              }

              matcher = null
              abPattern = null
            }
            return latency
          }
          {code}

          If I throw a @NonCPS on the inner `def matcher` it fixes it.
          New: I get java.io.NotSerializableException: java.util.regex.Matcher on:

          {code:groovy}
          @NonCPS
          def extractLatency(linesArr) {
            latency = [:]
            println "extractLatency"
            for (int j = 0; j < linesArr.size(); j++) {
              line = linesArr[j]
              println("looping over line: $line")
              // Matches lines like: Connect: 0 1 0.1 1 1
              abPattern = /(\w+)\:\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/

              def matcher = { (line =~ abPattern) }

              if (matcher().size > 1) {
                println("matched")
              }

              matcher = null
              abPattern = null
            }
            return latency
          }
          {code}

          If I throw a @NonCPS on the inner `def matcher` it fixes it.
          Jesse Glick made changes -
          Description Original: I get java.io.NotSerializableException: java.util.regex.Matcher on:

          {code:groovy}
          @NonCPS
          def extractLatency(linesArr) {
            latency = [:]
            println "extractLatency"
            for (int j = 0; j < linesArr.size(); j++) {
              line = linesArr[j]
              println("looping over line: $line")
              // Matches lines like: Connect: 0 1 0.1 1 1
              abPattern = /(\w+)\:\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/

              def matcher = { (line =~ abPattern) }

              if (matcher().size > 1) {
                println("matched")
              }

              matcher = null
              abPattern = null
            }
            return latency
          }
          {code}

          If I throw a @NonCPS on the inner `def matcher` it fixes it.
          New: I get {{java.io.NotSerializableException: java.util.regex.Matcher}} on:

          {code}
          @NonCPS
          def extractLatency(linesArr) {
            latency = [:]
            println "extractLatency"
            for (int j = 0; j < linesArr.size(); j++) {
              line = linesArr[j]
              println("looping over line: $line")
              // Matches lines like: Connect: 0 1 0.1 1 1
              abPattern = /(\w+)\:\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/

              def matcher = { (line =~ abPattern) }

              if (matcher().size > 1) {
                println("matched")
              }

              matcher = null
              abPattern = null
            }
            return latency
          }
          {code}

          If I throw a @NonCPS on the inner `def matcher` it fixes it.
          Jesse Glick made changes -
          Description Original: I get {{java.io.NotSerializableException: java.util.regex.Matcher}} on:

          {code}
          @NonCPS
          def extractLatency(linesArr) {
            latency = [:]
            println "extractLatency"
            for (int j = 0; j < linesArr.size(); j++) {
              line = linesArr[j]
              println("looping over line: $line")
              // Matches lines like: Connect: 0 1 0.1 1 1
              abPattern = /(\w+)\:\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/

              def matcher = { (line =~ abPattern) }

              if (matcher().size > 1) {
                println("matched")
              }

              matcher = null
              abPattern = null
            }
            return latency
          }
          {code}

          If I throw a @NonCPS on the inner `def matcher` it fixes it.
          New: I get {{java.io.NotSerializableException: java.util.regex.Matcher}} on:

          {code}
          @NonCPS
          def extractLatency(linesArr) {
            latency = [:]
            println "extractLatency"
            for (int j = 0; j < linesArr.size(); j++) {
              line = linesArr[j]
              println("looping over line: $line")
              // Matches lines like: Connect: 0 1 0.1 1 1
              abPattern = /(\w+)\:\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/

              def matcher = { (line =~ abPattern) }

              if (matcher().size > 1) {
                println("matched")
              }

              matcher = null
              abPattern = null
            }
            return latency
          }
          {code}

          If I throw a {{@NonCPS}} on the inner {{def matcher}} it fixes it.

          Jesse Glick added a comment -

          I assume this was a prototype on the way to a working function, since latency seems to be left empty, and matcher could simply be inlined.

          Probably the issue is just that @NonCPS is not inherited lexically.

          Jesse Glick added a comment - I assume this was a prototype on the way to a working function, since latency seems to be left empty, and matcher could simply be inlined. Probably the issue is just that @NonCPS is not inherited lexically.
          Jesse Glick made changes -
          Summary Original: java.io.NotSerializableException issues even with @NonCPS New: @NonCPS not lexically inherited
          Jesse Glick made changes -
          Epic Link New: JENKINS-35390 [ 171183 ]

          Trevor Hartman added a comment - - edited

          Yes, the println("matched") was placeholder logic.

          matcher couldn't be inlined from my experience. It kept throwing java.io.NotSerializableException: java.util.regex.Matcher until I put it in a lambda with @NonCPS.

          Trevor Hartman added a comment - - edited Yes, the println("matched") was placeholder logic. matcher couldn't be inlined from my experience. It kept throwing java.io.NotSerializableException: java.util.regex.Matcher until I put it in a lambda with @NonCPS .

            Unassigned Unassigned
            devth Trevor Hartman
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: