[
https://issues.apache.org/jira/browse/GROOVY-12672?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12672:
------------------------------------------
Affects Version/s: (was: 7.0.0-alpha-1)
> SC: a lambda that reads delegate, owner, resolveStrategy or
> maximumNumberOfParameters throws ClassCastException
> ---------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12672
> URL: https://issues.apache.org/jira/browse/GROOVY-12672
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> import groovy.transform.CompileStatic
> import java.util.function.Supplier
> @CompileStatic
> class C {
> def m() {
> Supplier<Object> s = () -> delegate
> s.get()
> }
> }
> assert new C().m() instanceof C
> {code}
> *Actual:* {{java.lang.ClassCastException: class java.lang.Class cannot be
> cast to class C$_m_lambda1}}. The same happens for {{owner}},
> {{maximumNumberOfParameters}}, {{resolveStrategy}}, {{parameterTypes}},
> {{directive}} and {{metaClass}}, in instance and static methods, in nested
> lambdas and in a lambda inside a closure. Assigning {{resolveStrategy}} fails
> with {{NoSuchMethodException: java.lang.Class.setProperty}}.
> *Expected:* the property is read from the lambda. {{delegate}} and {{owner}}
> are the enclosing object, as for {{thisObject}} and as the type checker
> infers; in a static method they are the class. 4.0.33 and 5.0.8 do not throw;
> they return the class for {{delegate}} and {{owner}}.
> Cause: since GROOVY-11905, a lambda that does not touch the enclosing
> instance gets a static {{doCall}}. Only {{this}}, {{super}} and
> {{thisObject}} counted as such access ({{StaticTypesLambdaAnalyzer}}), so a
> closure property is read from the enclosing Class instead of the lambda.
> Verified: 6.0.0 and master affected; 4.0.33 and 5.0.8 not affected.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)