You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Grzegorz Kaczmarczyk (Jira)" <ji...@apache.org> on 2020/08/11 08:26:00 UTC
[jira] [Updated] (GROOVY-9683) Changed behavior of delegates in
2.5.13
[ https://issues.apache.org/jira/browse/GROOVY-9683?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Grzegorz Kaczmarczyk updated GROOVY-9683:
-----------------------------------------
Description:
I've noticed difference in how maps behave when used as delegates between 2.5.12 (and earlier versions) and 2.5.13. Consider this code snippet:
{code:java}
class MapAsDelegateProblem {
static void main(String[] args) {
new MapAsDelegateProblem().problematicCode()
}
def problematicCode() {
def map = [:]
callForAProblem(map) {
assert "abc" == BAR
}
}
def <U> void callForAProblem(U target, Closure<?> closure) {
closure.setDelegate(target)
closure.setResolveStrategy(Closure.DELEGATE_FIRST)
closure.call(target)
}
private static final BAR = "abc"
} {code}
In 2.5.x (up to 2.5.12) this code works just fine. Static field {{BAR}} is accessed from closure in line 10. But this breaks in 2.5.13. This affects also tests written in Spock. Utility method {{spock.lang.Specification::with }}works in the same way as{{ callForAProblem}}.
was:
I've noticed difference in how maps behave when used as delegates between 2.5.12 (and earlier versions) and 2.5.13. Consider this code snippet:
{code:java}
class MapAsDelegateProblem {
static void main(String[] args) {
new MapAsDelegateProblem().problematicCode()
}
def problematicCode() {
def map = [:]
callForAProblem(map) {
assert "abc" == BAR
}
}
def <U> void callForAProblem(U target, Closure<?> closure) {
closure.setDelegate(target)
closure.setResolveStrategy(Closure.DELEGATE_FIRST)
closure.call(target)
}
private static final BAR = "abc"
} {code}
In 2.5.x (up to 2.5.12) this code works just fine. Static field {{BAR}} is accessed from closure in line 10. But this breaks in 2.5.13. This affects also tests written in Spock. Utility method {{spock.lang.Specification::with }}works in the same way as {{callForAProblem}}.
> Changed behavior of delegates in 2.5.13
> ---------------------------------------
>
> Key: GROOVY-9683
> URL: https://issues.apache.org/jira/browse/GROOVY-9683
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.5.13
> Reporter: Grzegorz Kaczmarczyk
> Priority: Major
>
> I've noticed difference in how maps behave when used as delegates between 2.5.12 (and earlier versions) and 2.5.13. Consider this code snippet:
> {code:java}
> class MapAsDelegateProblem {
> static void main(String[] args) {
> new MapAsDelegateProblem().problematicCode()
> }
> def problematicCode() {
> def map = [:]
> callForAProblem(map) {
> assert "abc" == BAR
> }
> }
> def <U> void callForAProblem(U target, Closure<?> closure) {
> closure.setDelegate(target)
> closure.setResolveStrategy(Closure.DELEGATE_FIRST)
> closure.call(target)
> }
> private static final BAR = "abc"
> } {code}
> In 2.5.x (up to 2.5.12) this code works just fine. Static field {{BAR}} is accessed from closure in line 10. But this breaks in 2.5.13. This affects also tests written in Spock. Utility method {{spock.lang.Specification::with }}works in the same way as{{ callForAProblem}}.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)