-
Notifications
You must be signed in to change notification settings - Fork 34
[JENKINS-26481] Patch DGM methods with closure parameters #52
Conversation
so returning the same type makes the patching code above easier
... that we need to rewrite differently.
While running tests, I came across a strange test failure where each(List,Closure) is delegating to each(Iterator,Closure) and results in a cast failure. Obviously, it shuold have resolved to each(Object,Closure) instead. This got me thinking about how Groovy resolves overloaded methods, which is non-trivial as a dynamic language. So in this change I'm changing the code so that Groovy doesn't have to resolve overloaded versions correctly.
The correct signature, which you can check in DefaultGroovyMethods, is to return the 'self' type
…if only once, rather than merely returning the list element.
The suspected cause of the problem is that DGMPatcher is not touching everything it needs to touch, when Groovy runtime is already warm and cached lots of MetaMethod objects. This test, having a name that is alphabetically before CpsTransformerTest, runs before that and populates the cache, exposing the defect in DGMPatcher. Run the test like this: mvn clean test -Dtest=AaaMakeGroovyBusy,CpsTransformerTest
…at elements overriding Object.equals.
... and cast wider net to traverse a bigger graph
…4' into DGMPatcher-Groovy-2-JENKINS-34064 Conflicts: src/main/java/com/cloudbees/groovy/cps/impl/DGMPatcher.java
Reverting cloudbees#38 in this branch.
…nued Conflicts: src/test/groovy/com/cloudbees/groovy/cps/CpsTransformerTest.groovy
Needs more tests for sets and map collect
@@ -14,6 +14,7 @@ | |||
|
|||
<properties> | |||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |||
<groovy.version>2.4.11</groovy.version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this will be usable only in 2.61+, right?
for (Iterator itr = ((ManagedConcurrentLinkedQueue) o).iterator(); itr.hasNext(); ) { | ||
Object item = itr.next(); | ||
if (patch(item) != item) { | ||
LOGGER.log(WARNING, "Can't replace members of ManagedConcurrentLinkedQueue", item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant
LOGGER.log(WARNING, "Can''t replace members of ManagedConcurrentLinkedQueue: {0}", item);
or more nicely
LOGGER.log(WARNING, "Cannot replace members of ManagedConcurrentLinkedQueue: {0}", item);
or
LOGGER.log(WARNING, "Can’t replace members of ManagedConcurrentLinkedQueue: {0}", item);
Object item = itr.next(); | ||
if (patch(item) != item) { | ||
LOGGER.log(WARNING, "Can't replace members of ManagedConcurrentLinkedQueue", item); | ||
// TODO would be possible, if necessary, by calling ManagedConcurrentLinkedQueue.Element.remove on *all* elements, then using ManagedLinkedList.add to recreate the entire list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly copy-paste error in comment
The manual changes to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying an alternative approach.
Closing in favor of #56, which now includes tests from here. |
JENKINS-26481
Subsumes #51 (which itself subsumes #24).
Note that this is currently a work in progress, adding patched methods one by one, but I wanted to get a PR open for watching the changes as we go.
cc @reviewbybees