-
Notifications
You must be signed in to change notification settings - Fork 34
Conversation
And of course if you update the |
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
With these additional changes the serialization test in question now passes for me. |
Awesome. Next week I will try to pick this up in an integration test. |
To make the |
@@ -285,6 +308,10 @@ private Object patch(Object o) { | |||
return o; | |||
} | |||
|
|||
private boolean isInstance(Class t, Object o) { |
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.
Clearer to inline this I think.
…if only once, rather than merely returning the list element.
The fix does not seem to work, either in the unit test here, or in the downstream integration test. The closure is run only once. |
Hmm, after diff --git a/pom.xml b/pom.xml
index f511471..3731571 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,7 +81,7 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
- <version>1.8.9</version>
+ <version>2.4.6</version>
<!--
let the user of this library select the right flavor of groovy,
including groovy vs groovy-all I tried
which succeeds, yet
fails:
|
After
here (without the Groovy version patch), from jenkinsci/workflow-cps-plugin#14
fails, as does
with
indicating again that the closure was run just once. |
This makes the unit test pass: diff --git a/pom.xml b/pom.xml
index f511471..ac21096 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,6 +54,14 @@
</dependency>
</dependencies>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.19.1</version>
+ <configuration>
+ <reuseForks>false</reuseForks>
+ </configuration>
+ </plugin>
</plugins>
<extensions>
<extension> |
The difference in behavior comes down to whether To see the failure it suffices to run
|
Successful run has:
whereas a failing run has:
|
I've tried all three ways you mention here in trying to reproduce the failure you are seeing, but to no avail thus far. |
|
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
Try with Java 8. Passes for me too in 7, but fails in 8. |
…but passes on 8 with Groovy 2.4.7. |
... 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
Since we've moved to Groovy 2.4.7 in 2.7.x and later lines, is it time to revisit this? |
You mean, assuming we drop 1.x support in Anyway I am not convinced |
Ok, I'm gonna try to get to understand this a bit. |
So it looks like https://issues.apache.org/jira/browse/GROOVY-6263 is the reason we can't use |
I have no clue what that comment refers to. FWIW I was not suggesting actually using |
fwiw, I've started testing with Groovy 2.5.0-alpha-1 and have hit errors in |
I tell a lie - the problem change actually happened in 2.4.. With the following code... import org.codehaus.groovy.runtime.InvokerHelper
public class A {
@Override
public String toString() {
return "base"
}
}
public class B extends A {
@Override
public String toString() {
return "x" + super.toString()
}
}
MetaClass mc = InvokerHelper.getMetaClass(B.class);
assert 'super$2$toString' == mc.getMethodWithCaching(B.class, "toString", null, true).getName(); ...it passes with 2.4.7 and fails with 2.4.8. That results in Gonna find the actual change that caused this now. =) |
And apache/groovy@0a6789d is the culprit commit. Now the question is do we want to open a bug against Groovy for this change from 2.4.7->2.4.8, or do we want to find a way to work around it in |
And as I keep digging - |
Found the problem commit in Groovy for |
Got it! |
Not quite sure what it is you are fixing here—do you think there are regressions in Groovy 2.4.8 that have not yet been found by users, or what? |
There definitely is - https://issues.apache.org/jira/browse/GROOVY-8140 is the |
So fwiw, https://github.com/abayer/groovy-cps/tree/jenkins-34064-continued, building against the latest Groovy 2.5.0-SNAPSHOT, has |
I just realized what you meant re |
Closing in favor of #51 |
BTW @abayer you do not need to close a PR which you propose to subsume in another PR; if the new one is merged, GH will automatically treat this one as merged, too. |
JENKINS-34064
Amends #23. Use with
workflow-cps-plugin
When running, say,
this still fails (
CpsDefaultGroovyMethods
does not get used), but at least the build runs. Without this patch, basically everything (e.g.,WorkflowTest#demo
) breaks.Have been trying to traverse the 2.x graph (as of groovy/groovy-core#395), so far without success:
@reviewbybees esp. @kohsuke