[JIRA] (JENKINS-61748) Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines
Title: Message Title Devin Nusbaum edited a comment on JENKINS-61748 Re: Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines Please take a look at [the content at the link in the error message|https://jenkins.io/redirect/pipeline-cps-method-mismatches/], specifically the section " Override Overrides of non-CPS-transformed methods". I think that in your case, if you add {{@NonCPS}} to this code, you will get the expected behavior:{code:java}@NonCPS // Add this annotationint compareTo(PriorityClosure o) { priority <=> o?.priority }{code}The reason you need to do this is that your {{PriorityClosure}} class, which is defined in a Pipeline and so all of its methods are CPS-transformed, is being passed to {{PriorityQueue}}, which is a normal Java standard library class and so is not CPS-transformed, so {{PriorityQueue.add}} is not able to call {{PriorityClosure.compareTo}} correctly. Add Comment This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-issues/JIRA.205578.1585611645000.7815.1586288762261%40Atlassian.JIRA.
[JIRA] (JENKINS-61748) Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines
Title: Message Title Devin Nusbaum commented on JENKINS-61748 Re: Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines Please take a look at the content at the link in the error message, specifically the section "Override of non-CPS-transformed methods". I think that in your case, if you add @NonCPS to this code, you will get the expected behavior: @NonCPS // Add this annotation int compareTo(PriorityClosure o) { priority <=> o?.priority } The reason you need to do this is that your PriorityClosure class, which is defined in a Pipeline and so all of its methods are CPS-transformed, is being passed to PriorityQueue, which is a normal Java standard library class and so is not CPS-transformed, so PriorityQueue.add is not able to call PriorityClosure.compareTo correctly. Add Comment This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-issues/JIRA.205578.1585611645000.7813.1586288762235%40Atlassian.JIRA.
[JIRA] (JENKINS-61748) Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines
Title: Message Title Ryan Fenton-Garcia commented on JENKINS-61748 Re: Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines I've done some digging, and I think this is related to: https://issues.jenkins-ci.org/browse/JENKINS-44924 But I'm not entirely sure. Add Comment This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-issues/JIRA.205578.1585611645000.3743.1585674540288%40Atlassian.JIRA.
[JIRA] (JENKINS-61748) Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines
Title: Message Title Ryan Fenton-Garcia updated an issue Jenkins / JENKINS-61748 Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines Change By: Ryan Fenton-Garcia I'm attempting to make use of the native Java priority queue in a pipeline job by defining the following custom class {code:java}import java.lang.Comparableclass PriorityClosure implements Comparable { int priority Closure closure int compareTo(PriorityClosure o) { priority <=> o?.priority } PriorityClosure(priority, closure) {this.priority = prioritythis.closure = closure }}{code}and then attempting to run the following function{code:java}importjava.util.PriorityQueue def someFunction() { def testQueue = new PriorityQueue() for (int i = 0; i < 23; i++) {int staticIteratorReference = itestQueue.add(new PriorityClosure( staticIteratorReference, {println "this is a test" })) } println "Test Queue is: ${testQueue}"}{code}I would expect to get a priority queue with all of my stuff in it, but instead, checking the output console, I receive the following:{code:java}[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to
[JIRA] (JENKINS-61748) Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines
Title: Message Title Ryan Fenton-Garcia updated an issue Jenkins / JENKINS-61748 Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines Change By: Ryan Fenton-Garcia I'm attempting to make use of the native Java priority queue in a pipeline job by defining the following custom class {code:java} import java.lang.Comparable class PriorityClosure implements Comparable { int priority Closure closure int compareTo(PriorityClosure o) { priority <=> o?.priority } PriorityClosure(priority, closure) {this.priority = prioritythis.closure = closure }}{code}and then attempting to run the following function{code:java} import def someFunction() { def testQueue = new PriorityQueue() for (int i = 0; i < 23; i++) {int staticIteratorReference = itestQueue.add(new PriorityClosure( staticIteratorReference, {println "this is a test" })) } println "Test Queue is: ${testQueue}"}{code} I would expect to get a priority queue with all of my stuff in it, but instead, checking the output console, I receive the following:{code:java}[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call java.util.PriorityQueue.add but wound up catching PriorityClosure.compareTo; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/[2020-03-30T23:13:51.564Z] expected to call
[JIRA] (JENKINS-61748) Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines
Title: Message Title Ryan Fenton-Garcia created an issue Jenkins / JENKINS-61748 Trying to use PriorityQueue.add with custom classes winds up catching CustomClass.compareTo in scripted pipelines Issue Type: Bug Assignee: Unassigned Components: workflow-cps-plugin Created: 2020-03-30 23:40 Environment: Windows Server 2016 Jenkins: 2.204.5 Pipeline: 2.6 Labels: pipeline workflow-cps-plugin java queue Priority: Minor Reporter: Ryan Fenton-Garcia I'm attempting to make use of the native Java priority queue in a pipeline job by defining the following custom class class PriorityClosure implements Comparable { int priority Closure closure int compareTo(PriorityClosure o) { priority <=> o?.priority } PriorityClosure(priority, closure) { this.priority = priority this.closure = closure } } and then attempting to run the following function def someFunction() { def testQueue = new PriorityQueue() for (int i = 0; i < 23; i++) { int staticIteratorReference = i testQueue.add(new PriorityClosure( staticIteratorReference, { println "this is a